2012년 10월 24일 수요일
2012년 10월 4일 목요일
if we added more codes in setter/getter methods, we must override them by ourself in inherited class.
if we added more codes in setter/getter methods, we must override them by ourself in inherited class.
@interface ParentClass:NSObject
@property (nonatomic) int type;
- (void)updateData;
@end
@implentation ParentClass
@synthesize type = _type;
- (void) setType:(int) pType {
_type = pType;
[self doSomething]; //added codes
}
- (void) updateData
{
self.type ++;
NSLog("%d",self.type);
}
- (void) doSomething
{
NSLog(@"ParentClass:doSomething called!!");
}
@end
@interface ChildClass: ParentClass
@end
@implementation ChildClass
@synthesize type = _type;
- (void) updateData {
[super updateData]; // doSomething is not called!!
}
- (void) doSomething
{
NSLog(@"ChildClass:doSomething called!!");
}
@end
changed this.
@implementation ChildClass
@synthesize type = _type;
_type = pType;
}
[super updateData]; // doSomething is called
}
{
NSLog(@"ChildClass:doSomething called!!");
}
@end
coz, @synthesize make default setter/getter methods by itself. so these methods are different from them that you implemented in super class.
2012년 10월 1일 월요일
피드 구독하기:
글 (Atom)