This article describes some of the considerations involved in creating different versions of your application, and discusses those aspects for which Core Data provides support.
Typically, as it evolves from one version to another there are numerous aspects of your application that change: the classes you implement, the user interface, the file format, and so on. You need to be aware of and in control of all these aspects; there is no API that solves the problems associated with all these—for example Cocoa does not provide a means to automatically update your user interface if you add a new attribute to an entity in your managed object model. Core Data does not solve all the issues of how you roll out your application. It provides support for a small—but important and non-trivial—subset of the tasks you must perform as your application evolves.
Core Data stores are conceptually bound to the managed object model used to create them. Since a model describes the structure of the data, changing a model will render it incompatible with (and so unable to open) the stores it previously created. If you change your schema, you therefore need to migrate the data in existing stores to new version. In general, managing all this yourself can be difficult.
Core Data provides support for model versioning, for mapping from one model to another, and for data migration. Moreover, it provides an infrastructure to support the process of migration, allowing you to focus on the details of conversion that are specific to your domain.
Model versioning allows you to specify and distinguish between different configurations of your schema.
How you create a versioned managed object model is discussed in “Versioning.”
Core Data also makes it easy to find the right model to open a given persistent store, as discussed in “Initiating the Migration Process.”
A mapping model parallels a managed object model, specifying how to transform objects in the source into instances appropriate for the destination.
How you create a mapping model is discussed in “Mapping Overview.”
On Mac OS X v10.6 and later, in some simple cases you may not need to create a mapping model. Instead, Core Data can infer the model from existing versions of the managed object model. There can be significant performance benefits if you can use this approach. This is described in “Lightweight Migration.”
Data migration allows you to convert data from one model (schema) to another, using mappings.
How you perform a migration is discussed in “Initiating the Migration Process,” with further details on how you can customize the process given in “Customizing the Migration Process.”
Although Core Data makes versioning and migration easier than would typically otherwise be the case, it is important to understand that these processes are still non-trivial in effect. You still need to carefully consider the implications of releasing and supporting different versions of your application.
Last updated: 2009-03-31