views:

149

answers:

5

I have been looking everywhere for an answer to this question - perhaps I'm looking in the wrong places. Also, I'm brand new to Objective C although I have around 10 years of experience as a developer.

for this code:

[receiver makeGroup:group, memberOne, memberTwo, memberThree];

what would the method definition look like?

- (void)makeGroup:(Group *)g, (NSString *)memberOne, ...?

Thanks for any help you can provide. I know this is probably very simple...

Thanks, R

A: 

EDIT: I answered the wrong question. Ignore this.

The correct way to do this is:

-(void)makeGroup:(Group *)g memberOne:(NSString *)memberOne memberTwo:(NSString *)memberTwo memberThree:(NSString *)memberThree {
    ...
}

The call will look like this:

[receiver makeGroup:group memberOne:memberOne memberTwo:memberTwo memberThree:memberThree];
MrHen
That doesn't match the OP's question. It looks more like he has a variable number of parameters.
Carl Norum
If the arguments are n-length he should use an array. But the answer above has the correct syntax regardless.
ExitToShell
The example in the original post is exactly the one from page 17 of the Objective-C 2.0 PDF, so I'm pretty sure he's asking about variable argument methods.
Carl Norum
@MrHen, you should be able to delete your post if you want to. It might help you from being downvoted into oblivion, too.
Carl Norum
It doesn't really bother me. If I wait until it gets -3 I get a badge for deleting it. :D
MrHen
+4  A: 

It looks like you have a method that can take a variable number of arguments. If that's the case, the definition would look something like:

- (void)makeGroup:(Group *)g, ...;

Check out NSString's stringWithFormat: or NSArray's arrayWithObjects: methods for examples.

Edit: Upon further documentation reading, it seems that you are looking at the exact example that's in the Objective-C 2.0 documentation. The declaration you're looking for is right at the bottom of page 36.

Carl Norum
oh no kidding? you literally mean "..." ? going to test that now.
R.J.
Bingo to your Edit: I had not made it yet to that page. On page 17 the call was listed with no reference to the declaration on 36. Thank you for your answer and for seeing the example.
R.J.
A: 

either you're looking for MrHen's answer if you're seeking to do your own class method or if you want to do them separately you write the following into your header file:

-(void)makeGroup:(Group *)g;
-(NSString *)memberOne;
David Schiefer
+1  A: 

You can receive an infinte number of arguments with an ellipsis (...). Check this for further details!

unset
+1  A: 

It would make more sense to have the members as a separate array argument, like -(void)makeGroup:(Group *)g members:(NSArray *)members. If you must do varargs (which is a pain), it should be written like -(void)makeGroup:(Group *)g members:(NSString *)firstMember, ....

Since I this is trying to figure out how an example method from the documentation would be declared, it would be like this:

- (void)makeGroup:(id)group, ...

Then you would start up the varags machinery with the group argument and use it to find the other arguments.

Chuck
ah, yes, however, I'm so new to this - I'm working my way through the objective-c programming language documentation here: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocObjectsClasses.html and I am coming across code snippets that I wish had the method declarations listed too.
R.J.