December 2018
Intermediate to advanced
414 pages
10h 19m
English
Consider the following code snippet:
// BadViewController.swiftclass BadViewController: UIViewController { init() { super.init(nibName: nil, bundle: nil) self.view = UIView(frame: .zero) } required init?(coder aDecoder: NSCoder) { fatalError() }}// inside another view controllerlet badViewController = BadViewController()present(badViewController, animated: true, completion: nil)
While everything looks correct on the surface, we have created the View property at initialization, which is not the way to set the View property on a view controller. Instead, you should use the loadView(), method to do this.
Read now
Unlock full access