Possible Duplicate:
How to create variable argument methods in Objective-C
Variable number of method parameters in Objective C - Need an example
Following is an example of a method having variadic arguments.
- (void)numberOfParameters:group,... {
NSLog(@"%@",group);
}
In above method, I know to access the first one of the variadic arguments. Would you please help me for accessing the others as well?
I am just going through ObjC.pdf & I am reading page number 35 & line number is 4
See this almost same question
-(void)yourMethods:(id)string1, ...{
NSMutableArray *arguments=[[NSMutableArray alloc]initWithArray:nil];
id eachObject;
va_list argumentList;
if (string1)
{
[arguments addObject: string1];
va_start(argumentList, string1);
while ((eachObject = va_arg(argumentList, id)))
{
[arguments addObject: eachObject];
}
va_end(argumentList);
}
NSLog(@"%@",arguments);
}
Call it with nil parameter at the end as:
[object yourMethods:arg1,arg2,arg3,nil];// object can be self
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With