• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ObjC Question - labeled arguments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC Question - labeled arguments


  • Subject: Re: ObjC Question - labeled arguments
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 21 May 2008 22:43:54 -0700


On 21 May '08, at 10:34 PM, Peter Zegelin wrote:

I'm thinking the method name is setWidth with two arguments, one unlabeled and the other labeled with 'height'.

Nope. The method name (also called the "selector") is all of the keywords concatenated together. So in your example the method name is "setWidth:height:".


I can see that coming from a C-style syntax you'd be thinking of the first keyword as being different from the rest and calling it the method name, but it's not. All the keywords are equal.

Other examples of a call and the method name:

[foo bar]		--> bar
[foo bar: 1]	--> bar:
[foo bar: 1 baz: 2]	--> bar:baz:

These are all entirely different method names. The second and third kind of look as though 'baz:' is an optional parameter, but it doesn't work that way. You have to implement all the methods separately. (And note that you could have a baz: method too, which looks as though the _first_ parameter were optional. Try that in C++!)

Try to avoid using unnamed keywords. The language may still support them, but they're obsolete and deprecated, and you'll hardly find any methods in any Cocoa API that use them.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >ObjC Question - labeled arguments (From: Peter Zegelin <email@hidden>)
 >Re: ObjC Question - labeled arguments (From: mmalc crawford <email@hidden>)
 >Re: ObjC Question - labeled arguments (From: Peter Zegelin <email@hidden>)

  • Prev by Date: Re: ObjC Question - labeled arguments
  • Next by Date: Re: ObjC Question - labeled arguments
  • Previous by thread: Re: ObjC Question - labeled arguments
  • Next by thread: Re: ObjC Question - labeled arguments
  • Index(es):
    • Date
    • Thread