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 not using the document architecture.
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSApplication *app = [[NSApplication alloc] init];
AppDelegate *appDelegate = [[AppDelegate alloc] init];
[app setDelegate:appDelegate];
[app run];
}
}
But with the document architecture, when I create a window (I know this is not the way to create one, but for simplicity) ...
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
NSWindow *window = [[NSWindow alloc] init];
}
... I receive the error below.
*** Assertion failure in -[NSApplication init], /SourceCache/AppKit/AppKit-1344.72/AppKit.subproj/NSApplication.m:1787
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.
https://i.stack.imgur.com/RR3nK.png
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 OpenUntitledDocumentAndDisplay:error:
inside of my appDelegate's applicationDidFinishLaunching:notification
method in which case the NSApplication might view this as creating a document too soon.
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?