开发者

Newbie Objective C developer question

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 pro开发者_运维问答vide. I know this is probably very simple...

Thanks, R


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.


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


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.


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;


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜