Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding a variadic method in objective-c

When subclassing in objective-c, how can I forward a call to the superclass in the case of a variadic method. By what should I replace the ??? below to send all the objects I got?

- (void) appendObjects:(id) firstObject, ...
{
   [super appendObjects: ???];
}
like image 820
Thomas Avatar asked Oct 21 '10 12:10

Thomas


1 Answers

You can't. To safely pass all the variadic arguments, you need a method to accept a va_list.

In super,

-(void)appendObjectsWithArguments:(va_list)vl {
  ...
}

-(void)appendObject:(id)firstObject, ...
  va_list vl;
  va_start(vl, firstObject);
  [self appendObjectsWithArguments:vl];
  va_end(vl);
}

And use [super appendObjectsWithArguments:vl] when you override the method in the subclass.

like image 121
kennytm Avatar answered Sep 30 '22 16:09

kennytm