How to use varargs….

      No Comments on How to use varargs….
Hi

Ever wondered how we give multiple button names in alert view other buttons section…and in many more scenarios..

Ok so how we define a function with varargs..

-(void)getMultipleString:(NSString*)firstString ,… NS_REQUIRES_NIL_TERMINATION;


Now the definition

-(void)getMultipleString:(NSString*)firstString ,… NS_REQUIRES_NIL_TERMINATION
{
va_list  t;
va_start(t, firstString);
id obj;
for (obj = firstString; obj != nil; obj = va_arg(t, id))
{
    NSLog(@”%@”,obj);
}
va_end(t);
}
How you call the method….

[self getMultipleString:@”myname”,@”YourName”, nil];

A pat on the back !!

Leave a Reply

Your email address will not be published. Required fields are marked *