Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC Question - labeled arguments




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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.