Regardless on which controller type (UIViewController, UITableViewController), the following line always yields null in the View
Instead of self.view.window use
[(YourAppDelegate *)[[UIApplication sharedApplication] delegate] window]
According to the documentation of UIView, the window property is nil if the view has not yet been added to a window which is the case when viewDidLoad is called.
self.view.window will be available in viewDidAppear:
override func viewDidAppear(_ animated: Bool) {
print(self.view.window)
let vc = self.storyboard?.instantiateViewController(identifier: "SecondViewController") as? SecondViewController
self.view.window?.rootViewController = vc
}