I need to add some codes when MyClass’s string value is changed.
So I’m trying to override a MyClass’s string property method.
But I have no idea.. so I do like following.
Is it correct?
How to override property’s method?
@interface MyClass{
NSString *string;
}
@property(retain, nonatomic) NSString *string;
@end
@implementation MyClass
- (void)setString:(NSString*)newString{
// want to add some codes.
[self setString:newString]; <= Is this correct?
}
@end
What you are probably more up to is this:
[self setString:newString]at this place would be a an endless recursive loop.[super setString:newString]should call the superlass’ setter. However, I never did that myself.