Hee
Does anybody know how to implement an method in objective c that will take an array of arguments as parameter such as:
[NSArray arrayWithObjects:@"A",@"B",nil];
The method declaration for this method is:
+ (id)arrayWithObjects:(id)firstObj...
I can’t seem to make such method on my own. I did the following:
+ (void) doSometing:(id)string manyTimes:(NSInteger)numberOfTimes;
[SomeClass doSometing:@"A",@"B",nil manyTimes:2];
It will give the warningtoo many arguments to function ‘doSometing:manyTimes:’
Thanks already.
The ellipsis (…) is inherited from C; you can use it only as the final argument in a call (and you’ve missed out the relevant comma in your example). So in your case you’d probably want:
or, if you want the count to be explicit and can think of a way of phrasing it well:
You can then use the normal C methods for dealing with ellipses, which reside in stdarg.h. There’s a quick documentation of those here, example usage would be:
EDIT: additions, in response to comments. You can’t pass the various things handed to you in an ellipsis to another function that takes an ellipsis due to the way that C handles function calling (which is inherited by Objective-C, albeit not obviously so). Instead you tend to pass the va_list. E.g.