Unified Contacts

12 September, 2013

Common Mistake: initWithCoder VS viewDidLoad

One of the common mistake is that initializing objects/variables in viewDidLoad method. However, the best place to initialize objects/variables in ViewController is initWithCoder. When creating new files of UIViewController, they do not contain this method, therefore type this method manually in .h and .m file.

Difference:
initWithCoder is called when using Storyboard which initialize ViewController object. Usually used to initialize objects/variables.
viewDidLoad is called when it is loaded into memory and it only happens once. Usually used to instantiate objects/variables.