How to avoid initial "Untitled" document?

Using the Xcode Document-based application template, an empty "Untitled" document appears when the app is launched. When I open an existing document, this causes all sorts of confusion in trying to connect IBOutlets to the new Document instance (as suggested in the old pre-storyboard documentation). Is there any way to just have the app launch with nothing but the menu bar?

Replies

I don't understand the problem, since it's not clear why you would have a problem with outlets and new documents specifically at launch, and not with new documents at other times. However, to answer your specific question, implement "applicationShouldOpenUntitledFile(_:)" in your app delegate and return false if your app is not prepared to create an untitled file yet.

Thanks. Your suggestion enables the App to behave as I wish.


The details of my problem with outlets and documents are no longer relevant, since I have figured a consistent way to deal with all the pieces in the .storyboard situation.


R

OK, a couple of other things to keep in mind:


— There's also an "applicationShouldHandleReopen(_:hasVisibleWindows:)" delegate method that has a similar role when the app is reactivated from the background with no open windows, or reactivated from the dock. The standard behavior in this case is to create an untitled document, which you may also want to suppress.


— Both of these delegate methods are subject to the behavior of window state restoration. When your app is re-launched after previously having been running, the window configuration is restored to what it was at the previous quit, and the auto-creation of an untitled document might not happen. Conversely, if there was an untitled document when you last quit, it will be recreated independently of the delegate methods.


These behaviors can be disabled by users in System Preferences, so it's worth making sure you get your intended results under all combinations of these factors.