• 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: Andrew Farmer <email@hidden>
  • Date: Wed, 21 May 2008 22:38:38 -0700

On 21 May 08, at 22:25, Peter Zegelin wrote:
- (void)reset:(RulerStyle*)newStyle:(int)newSide:(int)textLoc: (double)newScale;

That syntax is pretty obscure. Try reading it as

- (void)reset:(RulerStyle*)style
   newStyle:(int)newStyle
    newSide:(int)newSide
    textLoc:(double)newScale;

and see if that makes any more sense. (Some of the types seem a little odd for the argument names, but that's what the method signature reads as.)

If this still doesn't make sense, check the header file for the code you're interfacing with.

I probably should have explained that I am calling my own ruler implementation so that object and method is my own. In C++ it is:


void reset(RulerStyle* newStyle, int newSide, int textLoc, double newScale);

All right - so figure out what your method signature is supposed to be, and write it accordingly. In this case, what you probably want is


- (void)reset:(RulerStyle *newStyle)
      newSide:(int)newSide
      textLoc:(int)textLoc
     newScale:(double)newScale;

You'd call this as

[obj reset:style newSide:123 textLoc:456 newScale:3.14159];

or whatnot.

So my question is - is there a way to include the first label? I note that the examples in the ObjectiveC manual seem to leave the first one out also:

[myRect setWidth:10.0 :15.0]; ---> [myRect setWidth:10.0 height: 15.0];

They shouldn't - that's invalid. Every "label" is a component of the method name - [myRect setWidth:10.0 height:15.0] is calling a completely separate method from [myRect setWidth:10.0 somethingElse: 15.0].

Well that example is straight out of the manual:

<...>
This method name uses unlabeled arguments. Unlabeled arguments make it difficult to determine the kind and purpose of a method’s arguments. Instead, method names should include labels describing each of their arguments...

Interesting - I wasn't aware that unlabeled arguments existed (primarily because they're not used in Cocoa). I'd stay away from them, as they're strictly less clear than named arguments, and will probably confuse other programmers just as they did me._______________________________________________


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


  • Follow-Ups:
    • Re: ObjC Question - labeled arguments
      • From: Bill Bumgarner <email@hidden>
References: 
 >ObjC Question - labeled arguments (From: Peter Zegelin <email@hidden>)
 >Re: ObjC Question - labeled arguments (From: Andrew Farmer <email@hidden>)
 >Re: ObjC Question - labeled arguments (From: Peter Zegelin <email@hidden>)

  • Prev by Date: Re: ObjC Question - labeled arguments
  • Next by Date: Re: fundamental question: how do I call controller methods from other classes?
  • Previous by thread: Re: ObjC Question - labeled arguments
  • Next by thread: Re: ObjC Question - labeled arguments
  • Index(es):
    • Date
    • Thread