ObjC Properties vs iVars

About property and iVar usage in init/dealloc methods.

Technically one use properties if he wants to publish a member. Make it accessible and/or modifiable without exposing the structure of the class. Properties also allows you to run a code (accessors) when the property is set (setter method) or get (getter method) by someone.

Since Xcode @synthesize generates the getter/setter for a property automatically, private properties are started to use as a convenient way to store a reference by retaining/copying an object. Moreover it isn’t needed to explicitly define an ivar for a property. The iVar is automatically generated now.

The properties however can do some more than one expects. Of course it automatically deallocates the original object assigning a new value to it but also sends out KVO notifications and there can be additional code which run hitting the accessor.

Usage in init/dealloc is not recommended

There are more reasons why you shouldn’t have to call a property in Init/dealloc:

  • Subclasses have not yet been initialized or have already deallocated when init or dealloc methods execute, making accessor methods potentially unreliable
  • The setter can be an implemented method with other tasks or can be overridden in a descendant class and you never know what else will run calling the setter.
  • Moreover KVO notifications fire when the property changes and there can be listeners with additional code which also will run at that moment.

Either of them are desirable to run in a dealloc.