There is no reason to use Lazy Instantiation / Lazy Initialization if you find this confusing; just initialize the instance variables / properties in the init class methods and don't worry about that.
Since an object is created as a side effect of calling the getter method, it does not immediately become obvious that it is created at all, so one alternative, which also means that you can use the getter method, which generates the default compiler, must explicitly check it in addCard :
- (void)addCard:(Card *)card atTop:(BOOL)atTop { if (!self.cards) self.cards = [NSMutableArray new]; if (atTop) { [self.cards insertObject:card atIndex:0]; } else { [self.cards addObject:card]; } }
(and deleting the user-provided retrieval method)
However, the network effect is the same as the code you sent, except that self.cards will return nil until addCard is called, however I doubt it will cause a problem.
source share