Class

NSPersistentStoreCoordinator

A coordinator that uses the model to help contexts and persistent stores communicate.

Declaration

@interface NSPersistentStoreCoordinator : NSObject

Overview

Instances of NSManagedObjectContext 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 addPersistentStoreWithType:configuration:URL:options:error:), or by using persistentStoreForURL: or persistentStores. This allows you to to determine, for example, whether a store has already been added, or whether two objects come from the same store.

For more details about these tasks, see Using Persistent Stores in Core Data Programming Guide.

Topics

Initializing a Coordinator

- initWithManagedObjectModel:

Initializes the coordinator with a managed object model.

managedObjectModel

The coordinator’s managed object model.

Specifying Registered Store Types

registeredStoreTypes

Returns a dictionary of the registered store types.

+ registerStoreClass:forStoreType:

Registers a given NSPersistentStore subclass for a given store type string.

Configuring Persistent Stores

- addPersistentStoreWithType:configuration:URL:options:error:

Adds a new persistent store of a specified type at a given location, and returns the new store.

- addPersistentStoreWithDescription:completionHandler:

Adds a new persistent store of a specified description, and returns the new store.

- setURL:forPersistentStore:

Sets the URL for a given persistent store.

- removePersistentStore:error:

Removes a given persistent store.

- destroyPersistentStoreAtURL:withType:options:error:

Deletes (or truncates) the target persistent store in accordance with the store class' requirements.

- migratePersistentStore:toURL:options:withType:error:

Moves a persistent store to a new location, changing the storage type if necessary.

persistentStores

The persistent stores associated with the coordinator.

- persistentStoreForURL:

Returns the persistent store for the specified URL.

- URLForPersistentStore:

Returns the URL for a given persistent store.

name

Name of the coordinator.

Store Options

Use options dictionary keys to specify store behavior and characteristics.

Adding, Removing, and Deleting Stores

NSPersistentStoreCoordinatorStoresDidChangeNotification

Posted whenever persistent stores are added to or removed from a persistent store coordinator, or when store UUIDs change.

NSPersistentStoreCoordinatorStoresWillChangeNotification

Posted before the list of open persistent stores changes.

NSPersistentStoreCoordinatorWillRemoveStoreNotification

Posted whenever a persistent store is removed from a persistent store coordinator.

Executing Fetch Requests

- executeRequest:withContext:error:

Sends a request to all the persistent stores associated with the coordinator.

- performBlock:

Asynchronously performs the block on the coordinator's queue.

- performBlockAndWait:

Synchronously performs the block on the coordinator's queue.

Migrating and Versioning Stores

Migration Options

Specify migration options in the dictionary of options when you add a persistent store using addPersistentStoreWithType:configuration:URL:options:error:.

Versioning Support

Metadata keys you access when comparing store versions.

Working with Metadata

+ metadataForPersistentStoreWithURL:error:

Returns a dictionary that contains the metadata stored in the persistent store at the specified location.

Deprecated
- metadataForPersistentStore:

Returns a dictionary that contains the metadata currently stored and that will be stored in a given persistent store.

- setMetadata:forPersistentStore:

Sets the metadata stored in the persistent store during the next save operation executed on it to metadata.

Store Metadata

Use™ metadata dictionary keys to identify the store type and UUID.

Working with Spotlight

NSCoreDataCoreSpotlightDelegate

A delegate that supports Core Spotlight integration.

+ elementsDerivedFromExternalRecordURL:

Returns a dictionary containing the parsed elements derived from the Spotlight external record file that is specified by the given URL.

- importStoreWithIdentifier:fromExternalRecordsDirectory:toURL:options:withType:error:

Creates and populates a store with the external records found at a given URL.

Spotlight External Record Elements

Specify values for the parsed elements derived from the Spotlight external record file.

Discovering Object IDs

- managedObjectIDForURIRepresentation:

Returns an object ID for the specified URI representation of an object ID if a matching store is available, or nil if a matching store cannot be found.

Deprecated

NSPersistentStoreDidImportUbiquitousContentChangesNotification

Posted after records are imported from the ubiquitous content store.

Deprecated
NSPersistentStoreUbiquitousTransitionType

These constants are used as the value corresponding to the NSPersistentStoreUbiquitousTransitionTypeKey in the user info dictionary of NSPersistentStoreCoordinatorStoresWillChangeNotification and NSPersistentStoreCoordinatorStoresDidChangeNotification notifications to identify the type of event leading to a change.

Deprecated
+ removeUbiquitousContentAndPersistentStoreAtURL:options:error:

Deletes all ubiquitous content for all peers for the persistent store at a given URL and also delete the local store file.

Deprecated
+ setMetadata:forPersistentStoreOfType:URL:error:

Sets the metadata for a given store.

Deprecated
+ metadataForPersistentStoreOfType:URL:error:

Returns a dictionary containing the metadata stored in the persistent store at a given URL.

Deprecated
- unlock

Relinquishes a previously acquired lock.

Deprecated
- lock

Attempts to acquire a lock.

Deprecated
- tryLock

Attempts to acquire a lock.

Deprecated

Relationships

Inherits From

Conforms To

See Also

Store Coordination

NSPersistentStore

The abstract base class for all Core Data persistent stores.

NSPersistentStoreDescription

A description object used to create and load a persistent store.

NSPersistentStoreRequest

Criteria used to retrieve data from or save data to a persistent store.

NSPersistentStoreResult

The abstract base class for results returned from a persistent store coordinator.

NSPersistentStoreAsynchronousResult

A concrete class used to represent the results of an asynchronous request.

NSSaveChangesRequest

An encapsulation of a collection of changes to be made by an object store in response to a save operation on a managed object context.

NSAtomicStore

An abstract superclass that you subclass to create a Core Data atomic store.

NSAtomicStoreCacheNode

A concrete class that you use to represent basic nodes in a Core Data atomic store.

NSIncrementalStore

An abstract superclass defining the API through which Core Data communicates with a store.

NSIncrementalStoreNode

A concrete class used to represent basic nodes in a Core Data incremental store.