I want to override the getter and setter in my ObjC class using ARC.
.h File
@property (retain, nonatomic) Season *season;
.m File
@synthesize season;
- (void)setSeason:(Season *)s {
self.season = s;
// do some more stuff
}
- (Season *)season {
return self.season;
}
Am I missing something here?
Best Answer
Yep, those are infinite recursive loops. That's because
is translated by the compiler into
and
is translated into
Get rid of the dot-accessor
self.
and your code will be correct.This syntax, however, can be confusing given that your property
season
and your variableseason
share the same name (although Xcode will somewhat lessen the confusion by coloring those entities differently). It is possible to explicitly change your variable name by writingor, better yet, omit the
@synthesize
directive altogether. The modern Objective-C compiler will automatically synthesize the accessor methods and the instance variable for you.