title: How do I get the keyWindow reference in a swift app?
body: <p>In Objective-C in the viewDidLoad method of a UIViewController I do this to get the keyWindow reference in my iOS app:</p>
  
  <pre><code> UIWindow * keyWindow = [[UIApplication sharedApplication] keyWindow];
  </code></pre>
  
  <p>So, I am porting this view controller into Swift and I do this one the viewDidLoad call:</p>
  
  <pre><code>let window = UIApplication.sharedApplication().keyWindow
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>(lldb) po window
  nil
  </code></pre>
  
  <p>How can I get window to be a valid reference to the keyWindow of my application in swift?</p>