Class

NSPersistentContainer

A container that encapsulates the Core Data stack in your application.

Declaration

@interface NSPersistentContainer : NSObject

Overview

NSPersistentContainer simplifies the creation and management of the Core Data stack by handling the creation of the managed object model (NSManagedObjectModel), persistent store coordinator (NSPersistentStoreCoordinator), and the managed object context (NSManagedObjectContext).

Topics

Creating a Container

initWithName:

Initializes a persistent container with the given name.

initWithName:managedObjectModel:

Initializes a persistent container with the given name and model.

persistentContainerWithName:

Initializes a new persistent container using the provided name for the container.

persistentContainerWithName:managedObjectModel:

Initializes a new persistent container using the provided name and managed object model.

Configuring a Container

persistentStoreDescriptions

The persistent store descriptions used to create the persistent stores referenced by this persistent container.

loadPersistentStoresWithCompletionHandler:

Instructs the persistent container to load the persistent stores.

managedObjectModel

The model associated with this persistent container. (read-only)

name

The name of this persistent container. (read-only)

persistentStoreCoordinator

The persistent store coordinator associated with this persistent container. (read-only)

Accessing the Context(s)

newBackgroundContext

Creates a private managed object context.

performBackgroundTask:

Causes the persistent container to execute the block against a new private queue context.

viewContext

The managed object context associated with the main queue. (read-only)

Configuring the Store Location

defaultDirectoryURL

Creates the default directory for the persistent stores on the current platform.

Relationships

Inherits From

See Also

Core Data Stack

NSManagedObjectContext

An object representing a single object space or scratch pad that you use to fetch, create, and save managed objects.

NSPersistentStoreCoordinator

A coordinator that associates persistent stores with a model (or a configuration of a model) and that mediates between the persistent stores and the managed object contexts.

NSManagedObjectModel

An object that describes a schema—a collection of entities (data models) that you use in your application.