I expected [super class]
to return the superclass's class, however I found, using this code that it returns this class's class.
Code
NSLogObject([self class]);
NSLogObject([super class]);
NSLogObject([self superclass]);
NSLogBool([self class] == [super class]);
Output
[self class]: MainMenuScene
[super class]: MainMenuScene
[self superclass]: CCScene
[self class] == [super class]:[YES]
Can somebody explain why this happens please?. I expect it to return the same value as [self superclass]
.
Macros: ------- #define NSLogBool(i) NSLog(@"%s:[%@]", #i, (i) ? @"YES" : @"NO") #define NSLogObject(o) NSLog(@"%s:[%@]", #o, o)
[super class]
calls the super
method on the current instance (i.e. self
). If self had an overridden version, then it would be called and it would look different. Since you don't override it, calling [self class]
is the same as calling [super class]
.
super
refers to the method implementation in the superclass. If you don't override the method in your class, the implementation in your class and its superclass is the same.
Both [super class]
and [self class]
call the same method, defined on NSObject
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With