views:

66

answers:

2

All I knew is this: Objective-c allows us to forward method invocation to its super class by [super method] However I want forward the invocation to super.super; Skipping the immediately super class.

In c++ we can easily do these by typecasting ((GrandSuper*)object).method().

Is their any provision to do the same in objective c

+2  A: 

I think you need to use objc_msgSendSuper directly, i.e.

#include <objc/message.h>
...

struct objc_super theSuper = {self, [GrandSuper class]};
id res = objc_msgSendSuper(&theSuper, @selector(method));
KennyTM
Be careful if the selector returns a struct. You'll need to work out whether to use `objc_msgSendSuper` or `objc_msgSendSuper_stret`, which isn't always straightforward.
Tom Dalling
+2  A: 

It's probably a bad idea to do this, although it is possible. You probably want to think of a better way to achieve whatever you're trying to do.

Let's assume that you have three classes: Cat which inherits from Mammal which inherits from Animal.

If you are in the method -[Cat makeNoise], you can skip -[Mammal makeNoise] and call -[Animal makeNoise] like so:

-(void) makeNoise;
{
    void(*animalMakeNoiseImp)(id,SEL) = [Animal instanceMethodForSelector:@selector(makeNoise)];
    animalMakeNoiseImp(self, _cmd);
}
Tom Dalling
Thanks, I just wanted a quick fix.
shakthi