I cannot understand why my getter and setter code is not working. In some code example, I went over:
- (NSArray *)sushiTypes { return _sushiRolls; } - (void)setSushiTypes:(NSArray *)sushiRolls { [sushiRolls retain]; [_sushiRolls release]; _sushiRolls = sushiRolls; }
Then in:
- (void)viewDidLoad { [super viewDidLoad]; self.sushiTypes = [[NSArray alloc]initWithObjects:@"...]autorelease]; }
All this time worked, but the sushiTypes property sushiTypes never been declared. I (kind of) get how it works, as it works the same way as a setter / getter, regardless of whether it was synthesized or not.
But here is my code, and I get a compiler error with a property request. Did I miss something?
// #import "Temp0.h" @implementation Temp0 -(NSNumber *)x1 { return x1; } -(void)setx1:(NSNumber *)x { [x retain]; [x1 release]; x1 = x; } -(id)init { self.x1 = [[NSNumber alloc]initWithInt:1]; // Error on this line: // Setter method is needed to assign to object using property assignment syntax [super init]; } @end
Screenshot of this code and error in Xcode
source share