O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Document-Based Applications

Most applications create, manage, and edit documents. A document can be anything that stores persistent data. Moreover, these applications all duplicate common functionality, such as the ability to create new documents, open existing documents, and manage multiple open documents. Cocoa provides a multiple-document application architecture that implements most of the basic functionality shared by all document-based applications. Cocoa document-based application architecture centers on the NSDocument, NSDocumentController, and NSWindowController classes.

When developing a document-based application, most development effort is likely to be spent implementing subclasses of NSDocument ; any document-based application must have at least one NSDocument subclass, but may have more (think of AppleWorks, for example). In MVC terminology, an NSDocument is a controller object; it manages a document’s persistent data, and to project that data into a view. This means that minimally an NSDocument subclass must know how to load data into a form useable by the application, as well as how to store this data into a persistent form. A well-implemented document subclass also provides support for printing, undo/redo operations, and edited status tracking.

An NSDocumentController instance is the administrator of a document-based application. It is responsible for servicing user requests to create, open, and save documents. NSDocumentController serves the integral role of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required