11

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: ???];
}
Thomas
  • 10,358
  • 4
  • 27
  • 35

2 Answers2

8

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.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
0

Try this:

- (void) appendObjects:(id) firstObject, ...
{
   va_list args = &firstObject;
   [super appendObjects: args];
}

If that doesn't do the trick, read the manual pages on varargs.

NSResponder
  • 16,861
  • 7
  • 32
  • 46