我期望[super class]
返回父类(super class)的类,但是我发现,使用此代码返回父类(super class)的类。
代码
NSLogObject([self class]);
NSLogObject([super class]);
NSLogObject([self superclass]);
NSLogBool([self class] == [super class]);
输出
[self class]: MainMenuScene
[super class]: MainMenuScene
[self superclass]: CCScene
[self class] == [super class]:[YES]
有人可以解释为什么会发生这种情况吗?我希望它返回与
[self superclass]
相同的值。巨集:
-------
#定义NSLogBool(i)NSLog(@“%s:[%@]”,#i,(i)?@"is":@“否”)
#定义NSLogObject(o)NSLog(@“%s:[%@]”,#o,o)
最佳答案
[super class]
在当前实例上调用super
方法(即self
)。如果self具有覆盖的版本,则它将被调用,并且看起来会有所不同。由于不覆盖它,因此调用[self class]
与调用[super class]
相同。
关于ios - 为什么 "[self class] == [super class]"?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11827720/