---
title: NSPersistentStoreCoordinator
framework: coredata
role: symbol
role_heading: Class
path: coredata/nspersistentstorecoordinator
---

# NSPersistentStoreCoordinator

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

## Declaration

```swift
class NSPersistentStoreCoordinator
```

## Mentioned in

Setting up a Core Data stack manually Setting up a Core Data stack

## Overview

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

- [init(managedObjectModel:)](coredata/nspersistentstorecoordinator/init(managedobjectmodel:).md)
- [Store options](coredata/store-options.md)
- [Migration options](coredata/migration-options.md)
- [Store versions](coredata/store-versions.md)

### Managing configuration

- [name](coredata/nspersistentstorecoordinator/name.md)
- [managedObjectModel](coredata/nspersistentstorecoordinator/managedobjectmodel.md)
- [persistentStores](coredata/nspersistentstorecoordinator/persistentstores.md)

### Registering store types

- [registerStoreClass(_:type:)](coredata/nspersistentstorecoordinator/registerstoreclass(_:type:).md)
- [registerStoreClass(_:forStoreType:)](coredata/nspersistentstorecoordinator/registerstoreclass(_:forstoretype:).md)
- [registeredStoreTypes](coredata/nspersistentstorecoordinator/registeredstoretypes.md)

### Adding or removing a store

- [addPersistentStore(type:configuration:at:options:)](coredata/nspersistentstorecoordinator/addpersistentstore(type:configuration:at:options:).md)
- [addPersistentStore(ofType:configurationName:at:options:)](coredata/nspersistentstorecoordinator/addpersistentstore(oftype:configurationname:at:options:).md)
- [addPersistentStore(with:completionHandler:)](coredata/nspersistentstorecoordinator/addpersistentstore(with:completionhandler:).md)
- [remove(_:)](coredata/nspersistentstorecoordinator/remove(_:).md)

### Modifying a store

- [destroyPersistentStore(at:type:options:)](coredata/nspersistentstorecoordinator/destroypersistentstore(at:type:options:).md)
- [migratePersistentStore(_:to:options:type:)](coredata/nspersistentstorecoordinator/migratepersistentstore(_:to:options:type:).md)
- [replacePersistentStore(at:destinationOptions:withPersistentStoreFrom:sourceOptions:type:)](coredata/nspersistentstorecoordinator/replacepersistentstore(at:destinationoptions:withpersistentstorefrom:sourceoptions:type:).md)
- [destroyPersistentStore(at:ofType:options:)](coredata/nspersistentstorecoordinator/destroypersistentstore(at:oftype:options:).md)
- [migratePersistentStore(_:to:options:withType:)](coredata/nspersistentstorecoordinator/migratepersistentstore(_:to:options:withtype:).md)
- [replacePersistentStore(at:destinationOptions:withPersistentStoreFrom:sourceOptions:ofType:)](coredata/nspersistentstorecoordinator/replacepersistentstore(at:destinationoptions:withpersistentstorefrom:sourceoptions:oftype:).md)

### Managing a store’s location

- [setURL(_:for:)](coredata/nspersistentstorecoordinator/seturl(_:for:).md)
- [persistentStore(for:)](coredata/nspersistentstorecoordinator/persistentstore(for:).md)
- [url(for:)](coredata/nspersistentstorecoordinator/url(for:).md)

### Managing a store’s metadata

- [setMetadata(_:type:at:options:)](coredata/nspersistentstorecoordinator/setmetadata(_:type:at:options:).md)
- [metadataForPersistentStore(type:at:options:)](coredata/nspersistentstorecoordinator/metadataforpersistentstore(type:at:options:).md)
- [setMetadata(_:forPersistentStoreOfType:at:options:)](coredata/nspersistentstorecoordinator/setmetadata(_:forpersistentstoreoftype:at:options:).md)
- [metadataForPersistentStore(ofType:at:options:)](coredata/nspersistentstorecoordinator/metadataforpersistentstore(oftype:at:options:).md)
- [metadata(for:)](coredata/nspersistentstorecoordinator/metadata(for:).md)
- [setMetadata(_:for:)](coredata/nspersistentstorecoordinator/setmetadata(_:for:).md)
- [NSStoreTypeKey](coredata/nsstoretypekey.md)
- [NSStoreUUIDKey](coredata/nsstoreuuidkey.md)

### Deferring a store’s migrations

- [NSPersistentStoreDeferredLightweightMigrationOptionKey](coredata/nspersistentstoredeferredlightweightmigrationoptionkey.md)
- [finishDeferredLightweightMigrationTask()](coredata/nspersistentstorecoordinator/finishdeferredlightweightmigrationtask().md)
- [finishDeferredLightweightMigration()](coredata/nspersistentstorecoordinator/finishdeferredlightweightmigration().md)

### Performing tasks

- [perform(_:)](coredata/nspersistentstorecoordinator/perform(_:)-74udx.md)
- [performAndWait(_:)](coredata/nspersistentstorecoordinator/performandwait(_:)-15ude.md)
- [perform(_:)](coredata/nspersistentstorecoordinator/perform(_:)-7jqb.md)
- [performAndWait(_:)](coredata/nspersistentstorecoordinator/performandwait(_:)-d3kq.md)
- [execute(_:with:)](coredata/nspersistentstorecoordinator/execute(_:with:).md)

### Maintaining a record of changes

- [NSPersistentHistoryTrackingKey](coredata/nspersistenthistorytrackingkey.md)
- [currentPersistentHistoryToken(fromStores:)](coredata/nspersistentstorecoordinator/currentpersistenthistorytoken(fromstores:).md)

### Integrating with Spotlight

- [NSCoreDataCoreSpotlightExporter](coredata/nscoredatacorespotlightexporter.md)
- [NSCoreDataCoreSpotlightDelegate](coredata/nscoredatacorespotlightdelegate.md)
- [Spotlight record keys](coredata/spotlight-record-keys.md)
- [Showcase App Data in Spotlight](coredata/showcase-app-data-in-spotlight.md)

### Getting individual object identifiers

- [managedObjectID(forURIRepresentation:)](coredata/nspersistentstorecoordinator/managedobjectid(forurirepresentation:).md)

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

- [NSPersistentStoreCoordinatorStoresWillChange](foundation/nsnotification/name-swift.struct/nspersistentstorecoordinatorstoreswillchange.md)
- [NSPersistentStoreCoordinatorStoresDidChange](foundation/nsnotification/name-swift.struct/nspersistentstorecoordinatorstoresdidchange.md)
- [NSPersistentStoreCoordinatorWillRemoveStore](foundation/nsnotification/name-swift.struct/nspersistentstorecoordinatorwillremovestore.md)
- [Notification keys](coredata/notification-keys.md)

### Deprecated

- [Deprecated Symbols](coredata/nspersistentstorecoordinator-deprecated-symbols.md)

### Instance Methods

- [managedObjectID(for:)](coredata/nspersistentstorecoordinator/managedobjectid(for:).md)

### Structures

- [NSPersistentStoreCoordinator.RemoteChangeMessage](coredata/nspersistentstorecoordinator/remotechangemessage.md)
- [NSPersistentStoreCoordinator.StoresDidChangeAsyncMessage](coredata/nspersistentstorecoordinator/storesdidchangeasyncmessage.md)
- [NSPersistentStoreCoordinator.StoresDidChangeMessage](coredata/nspersistentstorecoordinator/storesdidchangemessage.md)

### Type Methods

- [cachedModelForPersistentStore(at:options:)](coredata/nspersistentstorecoordinator/cachedmodelforpersistentstore(at:options:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSLocking](foundation/nslocking.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Store Coordination

- [NSPersistentStore](coredata/nspersistentstore.md)
- [NSPersistentStoreDescription](coredata/nspersistentstoredescription.md)
- [NSPersistentStoreRequest](coredata/nspersistentstorerequest.md)
- [NSPersistentStoreResult](coredata/nspersistentstoreresult.md)
- [NSPersistentStoreAsynchronousResult](coredata/nspersistentstoreasynchronousresult.md)
- [NSSaveChangesRequest](coredata/nssavechangesrequest.md)
- [NSAtomicStore](coredata/nsatomicstore.md)
- [NSAtomicStoreCacheNode](coredata/nsatomicstorecachenode.md)
- [NSIncrementalStore](coredata/nsincrementalstore.md)
- [NSIncrementalStoreNode](coredata/nsincrementalstorenode.md)
