Use direct access in partially constructed states independent of ARC:
- (id)initWithReminder:(Reminder*)reminder_ { self = [super init]; if (self) { reminder = reminder_; // OR reminder = [reminder_ retain]; } return self; }
This is because self.whatever will cause other side effects, such as key-value notifications (KVO), or maybe your class implements (explicitly) or overrides the setWhatever: subclass setWhatever: - and this may lead to partial initialization an instance for other APIs (including its own) that rightly assume that they are dealing with a fully constructed object.
You can manually verify that the class is able to work in a partially initialized state, but this requires a lot of maintenance and (in truth) is impractical or impossible when other people want to subclass your class. This requires a lot of time and maintenance, and it does not have significant benefits, especially if you try to use this approach as a convention.
Thus, a uniform method that guarantees correctness is to use direct access in partially constructed states and to avoid the use of accessories.
Note. I use "partially built" because initialization is only half the image; -dealloc has similar reservations.
More information on why you should use direct access in partially constructed states (ARC || MRC) can be found here: Property initialization, dot notation
justin Nov 08 '11 at 19:50 2011-11-08 19:50
source share