• 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 Method naming
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC Method naming


  • Subject: Re: ObjC Method naming
  • From: Scott <email@hidden>
  • Date: Mon, 28 May 2001 14:12:45 -0700

Does this mean that I could write my method calls as:

[myRect setWidth:10.0, 10.5];

Would it be acceptable without any parameter names, just commas? Or, do I
have to use colons?

[myRect setWidth:10.0 :10.5];

Just trying to get as close to a c++ style calling structure as possible
since that's the way my brain's wired right now. Fewer keystrokes is
better.

Also, what does the minus sign ("-") mean in the declaration? I've seen the
plus sign used also. What's the difference? All it says in the docs is
"you could also use the plus sign..." but doesn't follow up with any meaning
behind it. And when I declare a method, do I HAVE to declare it with
parameter names or can I leave them out?

Ex.
- (void) setWidth:(float) w height:(float) h



Rock on!
Scott

P.S. I miss Bjarne Stroustrup!
------
"...there's no such thing as a plain name..."
http://www.domainjane.com



On 5/28/01 1:26 PM, "Nat!" <email@hidden> wrote:

> 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!
> _______________________________________________
> cocoa-dev mailing list
> email@hidden
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev


  • Follow-Ups:
    • Re: ObjC Method naming
      • From: "David W. Halliday" <email@hidden>
    • Re: ObjC Method naming
      • From: "David W. Halliday" <email@hidden>
    • Re: ObjC Method naming
      • From: Greg Titus <email@hidden>
    • Re: ObjC Method naming
      • From: Andreas Monitzer <email@hidden>
    • Re: ObjC Method naming
      • From: email@hidden
    • Re: ObjC Method naming
      • From: Finlay Dobbie <email@hidden>
References: 
 >Re: ObjC Method naming (From: Nat! <email@hidden>)

  • Prev by Date: Re: ObjC Method naming
  • Next by Date: Re: drawing with clearColor
  • Previous by thread: Re: ObjC Method naming
  • Next by thread: Re: ObjC Method naming
  • Index(es):
    • Date
    • Thread