Class

NSPersistentStore

The abstract base class for all Core Data persistent stores.

Overview

Core Data provides four store types—SQLite, Binary, XML, and In-Memory (the XML store is not available on iOS); these are described in Persistent Store Features. Core Data also provides subclasses of NSPersistentStore that you can use to define your own store types: NSAtomicStore and NSIncrementalStore. The Binary and XML stores are examples of atomic stores that inherit functionality from NSAtomicStore.

Subclassing Notes

You should not subclass NSPersistentStore directly. Core Data only supports subclassing of NSAtomicStore and NSIncrementalStore.

The designated initializer is init(persistentStoreCoordinator:configurationName:at:options:). When you implement the initializer, you must ensure you load metadata during initialization and set it using metadata.

You must override these methods:

Topics

Working with State Information

var type: String

The type string of the persistent store.

var persistentStoreCoordinator: NSPersistentStoreCoordinator?

The persistent store coordinator that loaded the persistent store.

var configurationName: String

The name of the managed object model configuration used to create the persistent store.

var options: [AnyHashable : Any]?

The options the store was initialized with.

var url: URL?

The URL for the persistent store.

var identifier: String!

The unique identifier for the persistent store.

var isReadOnly: Bool

A Boolean value that indicates whether the persistent store is read-only.

Managing Metadata

class func metadataForPersistentStore(with: URL)

Returns the metadata from the persistent store at the given URL.

class func setMetadata([String : Any]?, forPersistentStoreAt: URL)

Sets the metadata for the store at a given URL.

var metadata: [String : Any]!

The metadata for the persistent store.

func loadMetadata()

Instructs the persistent store to load its metadata.

Creating and Destroying a Persistent Store

func didAdd(to: NSPersistentStoreCoordinator)

Invoked after the persistent store has been added to the persistent store coordinator.

func willRemove(from: NSPersistentStoreCoordinator?)

Invoked before the persistent store is removed from the persistent store coordinator.

Supporting Migration

class func migrationManagerClass()

Returns the migration manager class for this store class.

Supporting Core Spotlight

var coreSpotlightExporter: NSCoreDataCoreSpotlightDelegate

The spotlight exporter associated with this persistent store.

Relationships

Inherits From

Conforms To

See Also

Creating Persistent Stores

class NSPersistentStoreDescription

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

class NSAtomicStore

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

class NSAtomicStoreCacheNode

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

class NSIncrementalStore

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

class NSPersistentStoreRequest

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

class NSPersistentStoreResult

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

class NSPersistentStoreAsynchronousResult

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

class NSIncrementalStoreNode

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

class 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.