Mac OS X Reference Library Apple Developer
Search

Overview of the Tutorial

The task goal of this tutorial is to create a document-based application that allows a user to display and modify information about a department, employees in the department, and managerial relationships between the employees. Each document (file) contains information about a single department and the employees associated with it. The application allows the user to save a document as a file and then reopen the file, and supports undo and redo.

The User Interface

The final user interface may look like that shown in Figure 1-1.

Figure 1-1  Final User Interface

Final User Interface

Note that the emphasis in this tutorial is on functionality. Little attempt is made to refine the user interface as would be appropriate in a shipping application. Moreover, the problem domain is chosen for consistency with other documentation and for clarity rather than for realism.

Tutorial Steps

This document is intended to give a high-level view of creating a functional application with little code. Although some explanation is given of what happens behind the scenes, this document does not give an in-depth analysis of the Core Data infrastructure.

  1. “Creating the Project, Model, and Interface”

    The first step illustrates the creation of a Core Data document-based project in Xcode. The major initial requirement is to create the data model, which you can use to automatically create a default user interface. Between Core Data and Cocoa bindings, this first step actually creates a fully functional application that meets most of the task goals without the need to write any code!

  2. “Creating a Custom Employee Class”

    This part shows you how to implement a custom class for the Employee entity.

  3. “Adding a Department Object”

    The first step deals only with employees. The next step is to add a Department object to the document and configure the user interface appropriately. One issue that arises here is ensuring the uniqueness of the department. You want to ensure that only one department is created per document.

  4. “Copy and Paste”

    This part of the tutorial illustrates one approach to supporting copy and paste in a Core Data application.

  5. “Localizing and Customizing Model Property Names and Error Messages”

    Sometimes the user generates more than one error in a single operation. Core Data provides a rich infrastructure for specifying constraints on data values and error checking, so it’s fairly easy to catch these mistakes, but it can be challenging to present the error messages in a useful way. NSDocument provides an API to allow alert panels to be customized, so you can tailor customize the error presented to the user to make it as informative as possible.

  6. “Document Metadata”

    Spotlight provides users with a means of searching for files quickly and easily. To support this, you need to associate metadata with your documents. Core Data makes it easy to do this, and to write the necessary importer.

  7. “A Sheet for Creating a New Employee”

    This part describes how you can use a sheet for data entry.

NSPersistentDocument Limitations

Although this tutorial does not aim to cover all the possible features you might implement in an application, some functionality is omitted due to limitations in NSPersistentDocument itself. Because of the way Core Data operates, it is not possible to easily support autosaving in an NSPersistentDocument-based application. Core Data cannot save to a store and maintain the same changed state in a managed object context, all while keeping an unsaved stack around as the current document. For similar reasons, NSPersistentDocument does not support Save To operations.




Last updated: 2009-02-04

Did this document help you? Yes It's good, but... Not helpful...