Cocoa’s Document-Based Architecture

MathPaper uses Cocoa’s document-based architecture, which relies on three classes — NSDocument, NSDocumentController, and NSWindowController — for managing its windows. Part of the Application Kit, the document-based architecture includes much of the functionality needed to create an application that can manage multiple windows, each containing its own document.

Working with the rest of the AppKit, the document-based architecture system provides for the following functionality, most of which is available via an application’s File (or Document) menu:

  • Creating new documents (File New)

  • Opening existing documents from files (File Open)

  • Saving files, either to the names from which they were opened or to new names (File Save, File Save As, File Save Copy As)

  • Reverting documents to the way that they are stored on the disk (File Revert to Saved)

  • Closing currently open files, first prompting to save the files if necessary (File Close)

  • Printing documents and modifying the current page layouts (File Print and File Page Setup)

  • Automatically handling the window’s modified status and title bar, and the application’s Window menu

All of these tasks are handled for us automatically by Cocoa’s document-based architecture system.

Get Building Cocoa Applications: A Step by Step Guide 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.