It's all about using idiomatically consistent code. If you structure your code correctly, there are many rules that guarantee that using accessor in init / dealloc is safe.
The big problem is that (as mmalc said) the code setting the state of the property by default should not go through the accessor, because it leads to various unpleasant problems. The trap is that there is no reason why init should configure the default state of a property. For a number of reasons, I switched to accessors that initialize themselves, such as a simple example:
- (NSMutableDictionary *) myMutableDict { if (!myMutableDict) { myMutableDict = [[NSMutableDictionary alloc] init]; } return myMutableDict; }
This style of property initialization allows you to delay a lot of initialization code, which may not actually be necessary. In the above case, init is not responsible for initializing the state of properties, and it is absolutely safe (even necessary) in order to use accessors in the init method.
Admittedly, this imposes additional restrictions on your code, for example, subclasses with custom accessories for a property in the superclass must call the supermarket, but these restrictions do not contradict other other restrictions common in Cocoa.
Louis Gerbarg Oct 22 '08 at 21:10 2008-10-22 21:10
source share