Chapter 9. Document-Based Cocoa Applications

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • How to use an NSDocument subclass to store your document data

  • How to use an NSWindowController subclass to organize and display your document interface

  • How to bind menu items to your documents using Interface Builder

Macintosh applications have presented user data as documents since the very beginning. A document is a convenient way to organize a user interface: a document can be displayed in its own window. A document is also a convenient way to organize file data: a document is its own self-contained file or bundle.

In Mac OS X, document-based apps can take many forms. The archetypical document-based application is TextEdit. You can open text files in TextEdit and display the content of those files in their own window. You can edit the content of a file directly in its window, and when you are done you can save and close the document. From there it's an easy jump to viewing Pages or Preview files as documents. If you're willing to relax the way you treat the user interface and how data is stored, you can view Mail, iChat, and Safari as document-based applications. E-mail messages are self-contained and Mail displays these messages either as their own windows, or in a one-window mail viewer. And sending a new mail message is a lot like saving and closing a text document.

So far you have seen how to use Cocoa to build small, single-window applications. And using those techniques, you can even build applications ...

Get Beginning, Mac OS® X Snow Leopard™ Programming 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.