Early view instantiation

Consider the following code snippet:

// BadViewController.swift
class
BadViewController: UIViewController {
init() {
super.init(nibName: nil, bundle: nil)
self.view = UIView(frame: .zero)
}

required init?(coder aDecoder: NSCoder) { fatalError() }
}

// inside another view controller
let 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.

Never initialize a view in the constructor of a UIViewControlleralways use loadView() to create them programmatically.