In Objective-C in the viewDidLoad method of a UIViewController I do this to get the keyWindow reference in my iOS app:
UIWindow * keyWindow = [[UIApplication sharedApplication] keyWindow]; So, I am porting this view controller into Swift and I do this one the viewDidLoad call:
let window = UIApplication.sharedApplication().keyWindow I am trying to understand why the window is nil. When I put a breakpoint right after that line I then inspect window in the console and I get this:
(lldb) po window nil How can I get window to be a valid reference to the keyWindow of my application in swift?
let window: UIWindow? = UIApplication.sharedApplication().windows[0] as? UIWindowmight present what you look for... or sincefunc viewDidAppear(_ animated: Bool)(until your view is visible!) you have direct access to the window viaself.view.window, maybe that is what you look for...