title: NSDocumentController currentDocument returning nil
body: <p>I'm working on my first Mac document-based application.</p>
  
  <p>I have subclassed <code>NSDocument</code>, reimplementing methods such as</p>
  
  <pre><code>- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError;
  - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError;
  - (void)makeWindowControllers;
  </code></pre>
  
  <p>The main window controller is a subclass of <code>NSWindowsController</code>, that contains two <em>NSViewController</em> subclasses.</p>
  
  <p>The problem I'm facing is that I need to have access to the current document from these view controllers. What I do is calling</p>
  
  <pre><code>MyDocument *myDocument = [[NSDocumentController sharedController] currentDocument];
  </code></pre>
  
  <p>At first, right after starting the application, a new document is created. Then, the main window and its view controllers are created, but the method above returns <em>nil</em>. Here's the log (using <em>NSLog</em>) I get:</p>
  
  <pre><code>Just created this new document: &lt;MyDocument: 0x10040ff10&gt;
  I'm in a view controller and current document is (null)
  </code></pre>
  
  <p>After that, creating a new document and calling this method results in a non-nil pointer, but it doesn't point at the right document, but to the first one:</p>
  
  <pre><code>Just created this new document: &lt;MyDocument: 0x100437e10&gt;
  I'm in a view controller and current document is &lt;MyDocument: 0x10040ff10&gt;
  </code></pre>
  
  <p>Notice that after the second document creation, <code>currentDocument</code> points to the first document and not to the second one.</p>
  
  <p>Any idea of what I'm missing or doing wrong here? When is <code>currentDocument</code> set for <code>NSDocumentController</code>?</p>