Currently, Apple's official recommendation:
- (id)init{ self = [super init]; if(self){ _rssItems = [[NSMutableArray alloc]init]; } return self; }
The idea is that init (specifically, in this case [super init] ) is allowed to return an object other than self, and the expected behavior in this case is to work with this object instead - the easiest way to deal with this is just to set self to what super returns. Also note that return self; works great, regardless of whether self zero or not, hence the inversion of your if .
Of course, most classes do not perform this switching trick, but this is good practice, since Apple expects everyone to use this exact template for their init , so even if your subclass is currently working without self assignment, they could easily change that future behavior without warning.
andyvn22
source share