What is the difference between viewDidLoad and awakeFromNib?

4

What is the main difference between viewDidLoad and awakeFromNib in Swift development for iOS?

    
asked by anonymous 03.11.2017 / 14:31

1 answer

8

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

    
04.11.2017 / 13:48