为什么"[self class] == [super class]"?

Jam*_*ter 6 oop class objective-c superclass ios

我希望[super class]返回超类的类,但我发现,使用此代码返回此类的类.

NSLogObject([self class]);
NSLogObject([super class]);
NSLogObject([self superclass]);
NSLogBool([self class] == [super class]);
Run Code Online (Sandbox Code Playgroud)

产量

[self class]: MainMenuScene
[super class]: MainMenuScene
[self superclass]: CCScene
[self class] == [super class]:[YES]
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么会这样吗?我希望它返回相同的值[self superclass].

Macros:
-------
#define NSLogBool(i)   NSLog(@"%s:[%@]", #i, (i) ? @"YES" : @"NO")
#define NSLogObject(o) NSLog(@"%s:[%@]", #o, o)

mpr*_*vat 6

[super class]super在当前实例上调用该方法(即self).如果self有一个被覆盖的版本,那么它将被调用,它看起来会有所不同.由于您没有覆盖它,因此调用[self class]与调用相同[super class].