Creating Source Code to Implement a Custom Managed Object Class

Create an NSManagedObject subclass for your entity to implement custom methods.

To implement a custom managed object class
  1. In the project navigator, select the managed object model.

  2. In the Entities table, select the entity or entities for which you want to create an NSManagedObject subclass.

  3. Choose Editor > Create NSManagedObject subclass.

  4. In the first dialog, select a data model, and click Next.

  5. Then select the entity you want to manage, and click Next

  6. In the next dialog, select the folder where you want the new files to be created and the group where you want the new files to appear in the project navigator.

  7. Click Create.

You must select an entity to enable the Create NSManagedObject subclass menu item.

After you create the files, Xcode adds them to the current target. Xcode also updates the model with the new class names for the entities. Make sure you save the file before you build your project.

If you want to use a different name for a managed object class than its entity name, then you must change the name in several places:

  • Rename the class in the header and implementation files using the source editor

  • Change the class name in the utility area

  • Rename the header and implementation files in the project navigator

Definitive Discussion

    Managed Objects