Can I do this in objective c?
@interface Foo : NSObject { int apple; int banana; } @property int fruitCount; @end @implementation Foo @synthesize fruitCount; //without this compiler errors when trying to access fruitCount -(int)getFruitCount { return apple + banana; } -(void)setFruitCount:(int)value { apple = value / 2; banana = value / 2; } @end
I use the class as follows:
Foo *foo = [[Foo alloc] init]; foo.fruitCount = 7;
However, my recipient and setter are not called. If I write instead:
@property (getter=getFruitCount, setter=setFruitCount:) int fruitCount;
My recipient receives a call, but the setter is still not called. What am I missing?
Thanks,
source share