Instance Method


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


func addPersistentStore(ofType storeType: String, configurationName configuration: String?, at storeURL: URL?, options: [AnyHashable : Any]? = nil) throws -> NSPersistentStore



A string constant (such as NSSQLiteStoreType) that specifies the store type—see Persistent Store Types for possible values.


The name of a configuration in the receiver's managed object model that will be used by the new store. The configuration can be nil, in which case no other configurations are allowed.


The file location of the persistent 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 and Migration Options. This value may be nil.


If a new store cannot be created, upon return contains an instance of NSError that describes the problem

Return Value

The newly-created store or, if an error occurs, nil.


See Also

Configuring Persistent Stores

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.

Persistent Store Types

Persist data through the available store types.

Store Options

Use options dictionary keys to specify store behavior and characteristics.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software