What is the main difference between viewDidLoad and awakeFromNib in Swift development for iOS?
What is the main difference between viewDidLoad and awakeFromNib in Swift development for iOS?
awakeFromNib
is a NSObject
method and is called as soon as the object is created from an Interface Builder file (eg .xib)
viewDidLoad
is a method of UIViewcontroller
called after the ViewController view is created
In other words awakeFromNib
is called on any object defined in the interface builder (subclasses of UITableViewCell, UIView, UIViewcontroller, etc). viewDidLoad
is only invoked in subclasses of UIViewcontroller
, regardless of the way the view was built. That is, even if the view is created programmatically, using loadView
, the method is called.
In summary, viewDidLoad
is normally used to initialize ViewControllers and awakeFromNib
is used for other classes created with Interface Builder like TableViewCells