我所知道的只是:Objective-c允许我们将方法调用转发给它的超类 [超级方法] 但是我希望将调用转发给super.super;跳过立即超级班。
在c ++中,我们可以通过类型转换((GrandSuper *)对象).method()来轻松完成这些。
他们的任何规定是否在目标c中做同样的事情
答案 0 :(得分:3)
我认为你需要use objc_msgSendSuper
directly,即
#include <objc/message.h>
...
struct objc_super theSuper = {self, [GrandSuper class]};
id res = objc_msgSendSuper(&theSuper, @selector(method));
答案 1 :(得分:3)
这样做可能是个坏主意,尽管有可能。您可能想要想出一个更好的方法来实现您想要做的任何事情。
假设您有三个类:Cat
继承自Mammal
的{{1}}。
如果您使用方法Animal
,则可以跳过-[Cat makeNoise]
并像这样致电-[Mammal makeNoise]
:
-[Animal makeNoise]
答案 2 :(得分:0)
我认为你也可以称超级超级:
[[[self super] super]functionOfInterest];