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 Method naming



Am Montag, 28. Mai 2001 um 20:41 schrieb Pedrum Mohageri:

I have a silly question about the style convention used in Objective C
code. Take this example from page 56 of the ObjC reference.

[myRect setWidth:10.0 height:15.0];

Does this mean there is a method called set with two parameters width and
height? Wouldn't that be represented like this:

[myRect set Width:10.0 height:15.0];

Or does it mean there a method called setWidth with two parameters, a
nameless one(default?) and height.

It means that there is a method called "setWidth:height:" that accepts two parameters. All the "parameter names" are concatenated _including_ the ':' to form the method name. That's important to know, when playing with selectors. Technically therefore both parameters are really nameless. Since the method declaration is also written in the non-concatenated form (just as you would call it):

- (void) setWidth:(float) w height:(float) h // compiles into setWidth:height:
{
...
}

you don't much notice it.


But what really happens is that [myRect setWidth:10.0 height:15.0] translates into

objc_msgSend( myRect, @selector( setWidth:height:), 10.0, 15.0);


Nat!


References: 
 >ObjC Method naming (From: Pedrum Mohageri <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.