I wanted to create UIViewController programmatically without nib, e.g.:
import UIKit
class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// code...
}
// code...
}
and used it like this:
let vc = MyViewController()
self.present(vc, animated: true, completion: nil)
However, the app crashed:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MyViewController" nib but the view outlet was not set.'
This is weird because I don't associate any nib files with this view controller.
Cleaning builds, deleting derived data, deleting the app, restarting simulator, Xcode and my Mac didn't work. Adding init()
and call super.init(nibName: nil, bundle: nil)
also doesn't help.
What's wrong with my code?