As far as I know you should always use accessors to access or modify a property, except in two scenarios:
- init
- dealloc
Don’t Use Accessor Methods in Initializer Methods and dealloc The only places you shouldn’t use accessor methods to set an instance variable are in initializer methods and dealloc. To initialize a counter object with a number object representing zero, you might implement an init.
This exceptions are because calling accessors when the view is not completely initialised might raise issues when overriding the setters/getters (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html)
So, according to this the use of accessors on viewDidLoad
should be perfectly fine, and even recommended, however in most of the codes available on internet developers use _ivars
on viewDidLoad
and I wonder why. Is there a reason for using property _ivars
instead of accessors in viewDidLoad
?