title: How to get Main Window (App Delegate) from other class (subclass of NSViewController)?
body: <p>I'm trying to change my windows content, from other class , that is subclass of NSViewController.I'm trying code below, but it doesn't do anything.</p>
  
  <pre><code>[NSApplication sharedApplication]mainWindow]setContentView:[self view]]; //code in NSViewController
  
  [NSApplication sharedApplication]mainWindow] // returns null
  </code></pre>
  
  <p>I tried to add</p>
  
  <pre><code>[window makeMainWindow];
  </code></pre>
  
  <p>in App Delegate class, but it won't help.</p>
  
  <p>Did I miss something? </p>
  
  <p>P.S. Also I'm using code below to call any delegate function in my class,</p>
  
  <pre><code> [(appDelegate *) [[NSApplication sharedApplication]delegate]MyMethod];
  </code></pre>
  
  <p>but I wonder is there something better, wihtout importing delegate class. Something like  this </p>
  
  <pre><code>[[NSApplication sharedApplication]delegate]MyMethod];
  </code></pre>
  
  <p>(it gives warning)</p>