In Cocoa Programming for Mac OS X (Hillegass), there is a class in chapter 19:
@interface BigLetterView : NSView {
NSColor *bgColor;
}
@property (strong) NSColor *bgColor;
@end
The accessor is defined like this:
- (void)setBgColor:(NSColor *)c {
bgColor = c;
[self setNeedsDisplay:YES]; }
This looked correct to me, but it creates an infinite loop: bgColor = c calls setBgColor:c
Is this code correct ?
How to redefine a setter? What do I need to compile this code ?
In modern Xcode/llvm you can clean up your code a bit.
Namely you dont need to declare neither a member variable as backing variable, nor a synthesize statement.
If you dont declase synthesize your self, a property
foowill have the backing variable_fooSo this code should work