<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSPersistentStoreCoordinator",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPersistentStoreCoordinator"
  },
  "title" : "NSPersistentStoreCoordinator"
}
-->

# NSPersistentStoreCoordinator

An object that enables an app’s contexts and the underlying persistent stores to work together.

```
class NSPersistentStoreCoordinator
```

## Overview

A managed object context uses a coordinator to facilitate the persistence of its entities in the coordinator’s registered stores. A context can’t function without a coordinator because it relies on the coordinator’s access to the managed object model. The coordinator presents its registered stores as an aggregate, allowing a context to operate on the union of those stores instead of on each individually. A coordinator performs its work on a private queue and executes that work serially. You can use multiple coordinators if the work requires separate queues.

Use a coordinator to add or remove persistent stores, change the type or location on-disk of those stores, query the metadata of a specific store, defer a store’s migrations, determine whether two objects originate from the same store, and so on.

## Topics

### Creating a persistent store coordinator

[`-  initWithManagedObjectModel:`](/documentation/CoreData/NSPersistentStoreCoordinator/init(managedObjectModel:))

Creates a persistent store coordinator with the specified managed object model.

[Store options](/documentation/CoreData/store-options)

The options keys that configure the behavior and characteristics of a persistent store.

[Migration options](/documentation/CoreData/migration-options)

The options keys that configure the migration behavior of a persistent store.

[Store versions](/documentation/CoreData/store-versions)

The metadata keys you use when comparing store versions.

### Managing configuration

[`name`](/documentation/CoreData/NSPersistentStoreCoordinator/name)

The coordinator’s name.

[`managedObjectModel`](/documentation/CoreData/NSPersistentStoreCoordinator/managedObjectModel)

The coordinator’s managed object model.

[`persistentStores`](/documentation/CoreData/NSPersistentStoreCoordinator/persistentStores)

The coordinator’s persistent stores.

### Registering store types

[`registerStoreClass(_:type:)`](/documentation/CoreData/NSPersistentStoreCoordinator/registerStoreClass(_:type:))

Registers a persistent store subclass using the specified store type.

[`+  registerStoreClass:forStoreType:`](/documentation/CoreData/NSPersistentStoreCoordinator/registerStoreClass(_:forStoreType:))

Registers a persistent store subclass using the specified store type identifier.

[`registeredStoreTypes`](/documentation/CoreData/NSPersistentStoreCoordinator/registeredStoreTypes)

The coordinator’s registered store types.

### Adding or removing a store

[`addPersistentStore(type:configuration:at:options:)`](/documentation/CoreData/NSPersistentStoreCoordinator/addPersistentStore(type:configuration:at:options:))

Adds a specific type of persistent store at the provided location.

[`-  addPersistentStoreWithType:configuration:URL:options:error:`](/documentation/CoreData/NSPersistentStoreCoordinator/addPersistentStore(ofType:configurationName:at:options:))

Adds a specific type of persistent store at the provided location.

[`-  addPersistentStoreWithDescription:completionHandler:`](/documentation/CoreData/NSPersistentStoreCoordinator/addPersistentStore(with:completionHandler:))

Adds a persistent store using the provided description.

[`-  removePersistentStore:error:`](/documentation/CoreData/NSPersistentStoreCoordinator/remove(_:))

Removes the specified persistent store from the coordinator.

### Modifying a store

[`destroyPersistentStore(at:type:options:)`](/documentation/CoreData/NSPersistentStoreCoordinator/destroyPersistentStore(at:type:options:))

Deletes a specific type of persistent store at the provided location.

[`migratePersistentStore(_:to:options:type:)`](/documentation/CoreData/NSPersistentStoreCoordinator/migratePersistentStore(_:to:options:type:))

Changes the location and, if necessary, the store type of the specified persistent store.

[`replacePersistentStore(at:destinationOptions:withPersistentStoreFrom:sourceOptions:type:)`](/documentation/CoreData/NSPersistentStoreCoordinator/replacePersistentStore(at:destinationOptions:withPersistentStoreFrom:sourceOptions:type:))

Replaces one persistent store with another.

[`-  destroyPersistentStoreAtURL:withType:options:error:`](/documentation/CoreData/NSPersistentStoreCoordinator/destroyPersistentStore(at:ofType:options:))

Deletes a specific type of persistent store at the provided location.

[`-  migratePersistentStore:toURL:options:withType:error:`](/documentation/CoreData/NSPersistentStoreCoordinator/migratePersistentStore(_:to:options:withType:))

Changes the location and, if necessary, the store type of the specified persistent store.

[`-  replacePersistentStoreAtURL:destinationOptions:withPersistentStoreFromURL:sourceOptions:storeType:error:`](/documentation/CoreData/NSPersistentStoreCoordinator/replacePersistentStore(at:destinationOptions:withPersistentStoreFrom:sourceOptions:ofType:))

Replaces one persistent store with another.

### Managing a store’s location

[`-  setURL:forPersistentStore:`](/documentation/CoreData/NSPersistentStoreCoordinator/setURL(_:for:))

Changes the location of the specified persistent store.

[`-  persistentStoreForURL:`](/documentation/CoreData/NSPersistentStoreCoordinator/persistentStore(for:))

Returns the persistent store for the specified file URL.

[`-  URLForPersistentStore:`](/documentation/CoreData/NSPersistentStoreCoordinator/url(for:))

Returns the location of the provided persistent store.

### Managing a store’s metadata

[`setMetadata(_:type:at:options:)`](/documentation/CoreData/NSPersistentStoreCoordinator/setMetadata(_:type:at:options:))

Updates the metadata of a specific type of persistent store at the provided location.

[`metadataForPersistentStore(type:at:options:)`](/documentation/CoreData/NSPersistentStoreCoordinator/metadataForPersistentStore(type:at:options:))

Returns the metadata of a specific type of persistent store at the provided location.

[`+  setMetadata:forPersistentStoreOfType:URL:options:error:`](/documentation/CoreData/NSPersistentStoreCoordinator/setMetadata(_:forPersistentStoreOfType:at:options:))

Updates the metadata of a specific type of persistent store at the provided location.

[`+  metadataForPersistentStoreOfType:URL:options:error:`](/documentation/CoreData/NSPersistentStoreCoordinator/metadataForPersistentStore(ofType:at:options:))

Returns the metadata of a specific type of persistent store at the provided location.

[`-  metadataForPersistentStore:`](/documentation/CoreData/NSPersistentStoreCoordinator/metadata(for:))

Returns the metadata of the specified persistent store.

[`-  setMetadata:forPersistentStore:`](/documentation/CoreData/NSPersistentStoreCoordinator/setMetadata(_:for:))

Updates the metadata for the specified persistent store.

[`NSStoreTypeKey`](/documentation/CoreData/NSStoreTypeKey)

A key that identifies the store type.

[`NSStoreUUIDKey`](/documentation/CoreData/NSStoreUUIDKey)

A key that provides the store’s UUID.

### Deferring a store’s migrations

[`NSPersistentStoreDeferredLightweightMigrationOptionKey`](/documentation/CoreData/NSPersistentStoreDeferredLightweightMigrationOptionKey)

The key for enabling deferred lightweight migrations.

[`-  finishDeferredLightweightMigrationTask:`](/documentation/CoreData/NSPersistentStoreCoordinator/finishDeferredLightweightMigrationTask())

Executes a single pending task of a deferred lightweight migration.

[`-  finishDeferredLightweightMigration:`](/documentation/CoreData/NSPersistentStoreCoordinator/finishDeferredLightweightMigration())

Executes all remaining tasks of a deferred lightweight migration.

### Performing tasks

[`perform(_:)`](/documentation/CoreData/NSPersistentStoreCoordinator/perform(_:)-74udx)

Executes the provided closure asynchronously on the coordinator’s queue and awaits the result.

[`performAndWait(_:)`](/documentation/CoreData/NSPersistentStoreCoordinator/performAndWait(_:)-15ude)

Executes the provided closure on the coordinator’s queue and waits for it to finish.

[`-  performBlock:`](/documentation/CoreData/NSPersistentStoreCoordinator/perform(_:)-7jqb)

Executes the provided closure asynchronously on the coordinator’s queue.

[`-  performBlockAndWait:`](/documentation/CoreData/NSPersistentStoreCoordinator/performAndWait(_:)-d3kq)

Executes the provided closure on the coordinator’s queue and waits for it to finish.

[`-  executeRequest:withContext:error:`](/documentation/CoreData/NSPersistentStoreCoordinator/execute(_:with:))

Executes the specified request on each of the coordinator’s persistent stores.

### Maintaining a record of changes

[`NSPersistentHistoryTrackingKey`](/documentation/CoreData/NSPersistentHistoryTrackingKey)

The key you use to enable persistent history tracking.

[`-  currentPersistentHistoryTokenFromStores:`](/documentation/CoreData/NSPersistentStoreCoordinator/currentPersistentHistoryToken(fromStores:))

Returns a single persistent history token representing all of the specified stores.

### Integrating with Spotlight

[`NSCoreDataCoreSpotlightExporter`](/documentation/CoreData/NSCoreDataCoreSpotlightExporter)

The key you use to specify your Core Spotlight delegate.

[`NSCoreDataCoreSpotlightDelegate`](/documentation/CoreData/NSCoreDataCoreSpotlightDelegate)

A set of methods that enable integration with Core Spotlight.

[Spotlight record keys](/documentation/CoreData/spotlight-record-keys)

The keys for the values that exist in Spotlight’s external record files.

[Showcase App Data in Spotlight](/documentation/CoreData/showcase-app-data-in-spotlight)

Index app data so users can find it by using Spotlight search.

### Getting individual object identifiers

[`-  managedObjectIDForURIRepresentation:`](/documentation/CoreData/NSPersistentStoreCoordinator/managedObjectID(forURIRepresentation:))

Returns the object identifier for the specified URI representation.

### Responding to changes of the coordinator’s registered stores

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/NSPersistentStoreCoordinatorStoresWillChange>

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/NSPersistentStoreCoordinatorStoresDidChange>

  <doc://com.apple.documentation/documentation/Foundation/NSNotification/Name-swift.struct/NSPersistentStoreCoordinatorWillRemoveStore>

[Notification keys](/documentation/CoreData/notification-keys)

The keys you use to retrieve values from a notification’s user info dictionary.

### Deprecated

[Deprecated Symbols](/documentation/CoreData/nspersistentstorecoordinator-deprecated-symbols)

Review unsupported symbols and their replacements.

### Instance Methods

[`managedObjectID(for:)`](/documentation/CoreData/NSPersistentStoreCoordinator/managedObjectID(for:))

[`-  managedObjectIDFromUTF8String:length:`](/documentation/CoreData/NSPersistentStoreCoordinator/managedObjectIDFromUTF8String:length:)

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSLocking`](/documentation/Foundation/NSLocking)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`Sendable`](/documentation/Swift/Sendable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)