A coordinator that uses the model to help contexts and persistent stores communicate.
- iOS 3.0+
- macOS 10.4+
- tvOS 9.0+
- watchOS 2.0+
- Core Data
NSManaged use a coordinator to save object graphs to persistent storage and to retrieve model information. A context without a coordinator is not fully functional as it cannot access a model except through a coordinator. The coordinator is designed to present a façade to the managed object contexts such that a group of persistent stores appears as an aggregate store. A managed object context can then create an object graph based on the union of all the data stores the coordinator covers.
Coordinators do the opposite of providing for concurrency—they serialize operations. If you want to use multiple threads for different write operations you use multiple coordinators. Note that if multiple threads work directly with a coordinator, they need to lock and unlock it explicitly.
Each coordinator (and thus container) may use different copies, and hence different versions, of a managed object model. This allows you to cleanly deal with file versioning.
The coordinator gives access to its underlying object stores. You can retrieve an object store when you first add one (using
add), or by using
persistent. This allows you to to determine, for example, whether a store has already been added, or whether two objects come from the same store.
You move a store from one location to another, or change the type of a store, using
Persistent Store(_: to: options: with Type:)
You can set metadata for a given store using the persistent store coordinator (
For more details about these tasks, see Using Persistent Stores in Core Data Programming Guide.