Jacobo Koenig
Jacobo Koenig

Reputation: 12514

Disable Document-Based functionality on a Cocoa Application

I started a Document-Based project on XCode for a MacOS project. I realize now that i don't need this functionality and its potentially causing problems and delays in my progress.

Is there a way to disable this functionality?

Upvotes: 1

Views: 584

Answers (1)

Bob
Bob

Reputation: 930

To keep documents from opening, all you have to do is implement application(_: openFile:) or application(_: openFiles:) in your app delegate. These are the methods that are called when any file is opened, and by default these messages are just shuffled off to NSDocumentController, which is responsible for the whole document-based-app thing. If you implement one of those methods to do something other than invoke the NSDocument architecture, you can keep the ability to open files while removing the rest of the document-based system.

Keep in mind, though, that menu items such as Open and Open Recent will still be routed to the NSDocumentController and use the old behavior. To completely remove the document-based functionality:

  • Get rid of your NSDocument subclass(es) (or just disable them)
  • Remove the references to those classes in your Info.plist
  • Remove any document-specific menu items (like Save)

    I'd recommend that you hang on to the Open item; being able to open documents is handy even in a single-window or shoebox app.

  • If you have an NSDocumentController or a subclass in your main nib file or main storyboard scene, remove it or at the very least make sure that no actions are explicitly routed to it

  • If you have any code that uses NSDocumentController, get rid of it

Upvotes: 1

Related Questions