Recent review of learn objective-C on the Mac
In Chapter 4th, [Super setfillcolor: C] is called for rewriting. It may be because the translation logic is unclear. I wrote a small example to understand it.
Define a father class and son class
Father:
#import <Foundation/Foundation.h>@interface father : NSObject{ int num;}-(void)setNum:(int)num;@end
#import "father.h"@implementation father-(void)setNum:(int)c{ num = c; NSLog(@"i am father");}@end
Son:
#import <Foundation/Foundation.h>#import "father.h"@interface son : father-(void)setNum:(int)num;@end
# Import "son. H "@ implementation son-(void) setnum :( INT) c {num = C; if (1 = num) {nslog (@" I am Son ");} [Super setnum: C]; // The key here} @ end
Main:
#import <Foundation/Foundation.h>#import "son.h"int main(int argc, const char * argv[]){ @autoreleasepool { son *ii = [[son alloc]init]; [ii setNum:1]; } return 0;}
Output result:
2014-08-06 11:00:35.731 testtest[13606:303] i am son2014-08-06 11:00:35.732 testtest[13606:303] i am father
If [Super setnum: C] is removed, only I am son is output. Obviously, the subclass rewrite method adds its own features, while the [Super method] is used to retain the features of the parent class.