I am learning Cocoa, and my understanding from reading the documentation is that when the application starts, the following happens:
- A shared application instance has been created.
- The main nib file is viewed from the list of application properties, so the application knows which nib to load.
- a run loop starts.
This is good and makes sense for a single windowed application, but I'm confused about what xcode does when creating a document-based application.
In this case, there are two nib files; the first contains the application menu, and the second contains a window that represents the NSDocument subclass. when the application starts, a new document window opens.
Based on my understanding of how the application works above, I do not understand how my application knows how to open a document window after the nib menu has been viewed from the property list. There is no code created for this, as far as I can see (except for the windowNibName method, but where is it called from?)
Can someone tell me what xcode does differently so that the application finds out that it is based on a document and so you need to open a document window?
Update:
I am trying to understand how Xcode knows how to do something different if my application is configured as a document-based application and not a single window. To my knowledge, there is no setting to indicate this, and Xcode does not seem to generate any code to give this other behavior.
From reading documents over the last couple of days, I think I know how this works, but I'm not sure:
- _NSApplication_has applicationOpensUntitledFile delegate method that is called by the application delegate.
- NSDocumentController is set as the default application delegate, and the default implementation looks for CFBundledTypeInfo to determine whether the document is documented or not, and responds as appropriate for the application (IE YES for document-based applications and NO for single-window applications).
- In most cases, when a single application window is created, the application delegate is replaced with a custom AppController in any case, which usually does not contain the definition of the applicationOpenUntitledFile method, since it is not suitable for the type of application.
We hope that any Cocoa expert can confirm whether I understood correctly or if I bark the wrong tree.
Benjamin gale
source share