How do you call a method for an Objective-C object's superclass from elsewhere?

Posted by executor21 on Stack Overflow See other posts from Stack Overflow or by executor21
Published on 2010-05-20T19:45:37Z Indexed on 2010/05/20 20:20 UTC
Read the original article Hit count: 201

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?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about override