Implement a Document-Based Application

It is possible to put together a document-based application without having to write very much code. If your requirements are minimal, the Application Kit provides you with a default NSWindowController instance and a default NSDocumentController instance. You just have to create a multidocument project, compose the human interface, implement a subclass of NSDocument, and add any other custom classes or behavior required by your application.

The following procedures step you through the creation of a very simple rich text (RTF) editor. In a few minutes, and with only a few lines of code, you’ll have an application that—without Cocoa’s help—would have taken days or weeks to construct and debug.

The Document-Based Application Package

Project Builder provides a Document-Based Application project template to expedite the development of these kinds of applications. This project type provides the following things:

  • The application’s main nib file. This nib file contains a standard Cocoa application menu bar. The menu items in the File and Edit menus are already connected to appropriate first responder action methods.

  • A nib file for the application’s document. This nib file contains a single window to which other UI items can be added. A subclass of NSDocument named MyDocument has been made File’s Owner of the nib file. It (and therefore the MyDocument subclass) has an outlet to its window.

  • A skeletal NSDocument subclass implementation. The project ...

Get Learning Cocoa now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.