title: NSWindow returns nil (NSApplication)
body: <p>I've come across an issue where I cannot access my app's main window,
  as it returns <strong>nil</strong>.</p>
  
  <pre><code>let window = NSApplication.sharedApplication().mainWindow
  </code></pre>
  
  <p>I've found similar questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/7620251/how-to-get-main-window-app-delegate-from-other-class-subclass-of-nsviewcontro">How to get Main Window (App Delegate) from other class (subclass of NSViewController)?</a></p>
  
  <p>But doing:</p>
  
  <pre><code>let window = (NSApplication.sharedApplication() as! NSArray).objectAtIndex(0)
  </code></pre>
  
  <p>Doesn't seem to work either.</p>
  
  <p>Do I have to mess around in Storyboard?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I'm actually trying to port something from Objective-C.</p>
  
  <pre><code>    NSWindow *mainWindow = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
      NSLog(@"%@", mainWindow.contentViewController);
  </code></pre>
  
  <p>This returns a proper value, when put in the <code>viewDidLoad()</code> block in a <code>NSViewController</code>, so I'm guessing there is something wrong with <code>NSApplication.sharedApplication()</code>.</p>