I'm kinda new to Cocoa and I find it hard to tell when to use NSDocument-based architecture vs normal NSApplication to create my application.
I'm creating these toys project to learn Cocoa:
Which one of these should I make as NSDocument-based app?
I will certainly use CoreData whenever I can, but NSDocument and normal NSApplication work with CoreData so I'm not sure if this is relevant to my question.
You can use NSDocument
whenever the notion of documents makes sense with your application. This is up to you to define what a document is.
An example with a todo list app:
If you want to manage a single todo list or a single database containing several todo lists (an approach similar to iPhoto with images or iTunes with songs), then NSApplication
is OK.
If you want that each todo list be stored in a separate file and to be able to open several todo lists in as many windows in your application (an approach similar to TextEdit with text or Preview with images), then NSDocument
is worth considering.
The question to ask is not whether you should use NSDocument, but whether you intend to make a document-oriented application. Examples #1, #3, and possibly #5 are apps you could make document-centered (as opposed to library-centered).
Once you've decided whether your app uses documents, the answer to whether you should use NSDocument follows directly from that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With