Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use NSDocument-based architecture?

Tags:

cocoa

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:

  1. To-Do list app
  2. Chat program (like Adium)
  3. Finance app (Simple double-entry accouting)
  4. Personal bookmark app
  5. CRM-like contact management

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.

like image 915
Teo Choong Ping Avatar asked Dec 10 '22 19:12

Teo Choong Ping


2 Answers

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.

like image 58
mouviciel Avatar answered Dec 12 '22 08:12

mouviciel


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.

like image 39
Peter Hosey Avatar answered Dec 12 '22 08:12

Peter Hosey