Instance Method


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


func migratePersistentStore(_ store: NSPersistentStore, to URL: URL, options: [AnyHashable : Any]? = nil, withType storeType: String) throws -> NSPersistentStore



A persistent store.


An URL object that specifies the location for the new store.


A dictionary containing key-value pairs that specify whether the store should be read-only, and whether (for an XML store) the XML file should be validated against the DTD before it is read. For key definitions, see Store Options.


A string constant (such as NSSQLiteStoreType) that specifies the type of the new store—see Persistent Store Types.


If an error occurs, upon return contains an instance of NSError that describes the problem.

Return Value

If the migration is successful, the new store, otherwise nil.


This method is typically used for “Save As”€ operations. Performance may vary depending on the type of old and new store. For more details of the action of this method, see Persistent Store Features in Core Data Programming Guide.

See Also

Configuring Persistent Stores

func addPersistentStore(ofType: String, configurationName: String?, at: URL?, options: [AnyHashable : Any]?) -> NSPersistentStore

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

func setURL(URL, for: NSPersistentStore) -> Bool

Sets the URL for a given persistent store.

func remove(NSPersistentStore)

Removes a given persistent store.

func destroyPersistentStore(at: URL, ofType: String, options: [AnyHashable : Any]?)

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

var persistentStores: [NSPersistentStore]

The persistent stores associated with the coordinator.

func persistentStore(for: URL) -> NSPersistentStore?

Returns the persistent store for the specified URL.

func url(for: NSPersistentStore) -> URL

Returns the URL for a given persistent store.

var name: String?

Name of the coordinator.

Store Options

Use options dictionary keys to specify store behavior and characteristics.