title: NSApplication init failure: Creating more than one Application
body: <p>I am working with the document architecture in Cocoa but will create my own window instead of a nib. I am replacing NSApplicationMain with code that has worked for apps <em>not</em> using the document architecture.</p>
  
  <pre><code>int main(int argc, const char * argv[]) {
      @autoreleasepool {
          NSApplication *app = [[NSApplication alloc] init];
          AppDelegate *appDelegate = [[AppDelegate alloc] init];
          [app setDelegate:appDelegate];
          [app run];
      }
  }
  </code></pre>
  
  <p>But with the document architecture, when I create a window (I know this is not the way to create one, but for simplicity) ...</p>
  
  <pre><code>- (void)applicationDidFinishLaunching:(NSNotification *)notification {
      NSWindow *window = [[NSWindow alloc] init];
  }
  </code></pre>
  
  <p>... I receive the error below.</p>
  
  <pre><code>*** Assertion failure in -[NSApplication init], /SourceCache/AppKit/AppKit-1344.72/AppKit.subproj/NSApplication.m:1787
  </code></pre>
  
  <p>I have read the entire guide on the document architecture, tried creating the window many places, and have taken careful consideration to fit the procedure that the architecture supports, as the image with link below shows.</p>
  
  <p><a href="http://i.stack.imgur.com/RR3nK.png" rel="nofollow">http://i.stack.imgur.com/RR3nK.png</a></p>
  
  <p>Everything I've tried leads to the error above whenever I create a window, regardless of where I create it. One possible source of error is that I begin the document creation process with the <code>OpenUntitledDocumentAndDisplay:error:</code> inside of my appDelegate's <code>applicationDidFinishLaunching:notification</code> method in which case the NSApplication might view this as creating a document too soon.</p>
  
  <p>In brief, why does creating a window object in the document architecture result in an NSApplication error, specifically that I'm creating more than one application?</p>