views:

216

answers:

2

If you're implementing a subclass, you can, within your implementation, explicitly call the superclass's method, even if you've overridden that method, i.e.:

[self overriddenMethod]; //calls the subclass's method
[super overriddenMethod]; //calls the superclass's method

What if you want to call the superclass's method from somewhere outside the subclass's implementation, i.e.:

[[object super] overriddenMethod]; //crashes

Is this even possible? And by extension, is it possible to go up more than one level within the implementation, i.e.:

[[super super] overriddenMethod]; //will this work?
+3  A: 

You can send [[[object class] superclass] methodForSelector: ...] and invoke through the IMP pointer directly, if you want... but if you're doing this, there's probably something very wrong with your application's design.

Nicholas Riley
Not design. Need this for debugging.
executor21
In that case, IMP away. :)
Nicholas Riley
+6  A: 

A more pleasant option (for debugging) is to add a category method which does it for you:

- (void) callSuperMethod { [super overriddenMethod]; }

The fact that there’s no more convenient way to do this is very much by design.

Ahruman