Junior — Senior
Determine the order of calling UIViewController lifecycle methods
livecode
Task condition
The example below shows a custom controller inheriting from UIViewController, in which the main lifecycle methods, as well as initializers and the destructor, are overridden. You need to understand the sequence in which messages will be output to the console during the creation of the controller instance, its display on the screen, and subsequent removal.
import UIKit
import PlaygroundSupport
class SampleVC: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("viewWillAppear")
}
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad")
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
print("init(nibName:bundle:)")
}
override func loadView() {
super.loadView()
print("loadView")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print("viewDidAppear")
}
required init?(coder: NSCoder) {
super.init(coder: coder)
print("init(coder:)")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("viewWillDisappear")
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
print("viewDidDisappear")
}
deinit {
print("deinit")
}
}