I have a integer variable, for example, timeSignature, declared it in .h file, and synthesized a pair of setter/getter methods:
in .h:
@interface Metronome : NSObject {
int timeSignature;
}
@property (nonatomic) int timeSignature;
in .m:
@synthesize timeSignature;
I wish to override the setter method: when user set a new value to it, it does something else as well as changing to new value:
- (void) setTimeSignature:(int)timeSignature {
self.timeSignature = timeSignature; //hides instance variable warning at this line
[self doesSomethingElse];
}
And heres the problem, the local variable and the instance variable have the same name.
How can I avoid this?
Name your ivar
_timeSignatureand make@synthesize timeSignature = _timeSignature;