Model File Format and Versions

A managed object model that supports versioning is represented in the filesystem by a .xcdatamodeld document. An .xcdatamodeld document is a file package (see Document Packages in Bundle Programming Guide) that groups versions of the model, each represented by an individual .xcdatamodel file, and an Info.plist file that contains the version information.

The model is compiled into a runtime format—a file package with a .momd extension that contains individually compiled model files with a .mom extension. You load the .momd model bundle using NSManagedObjectModel’s initWithContentsOfURL:.

To add a version to a model, you start with a model such as that illustrated in Figure 2-1.

Figure 2-1  Initial version of the Core Recipes model

To add a version, select Editor > Add Model Version. In the sheet that appears, you enter the name of the new model version and select the model on which it should be based.

To set the new model as the current version of the model, select the .xcdatamodeld document in the project navigator, then select the new model in the pop-up menu in the Versioned Core Data Model area in the Attributes Inspector (see Figure 2-2).

Figure 2-2  Version 2 of the Core Recipes model