Class

NSPersistentContainer

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

Overview

NSPersistentContainer simplifies the creation and management of the Core Data stack by handling the creation of the NSManagedObjectModel, NSPersistentStoreCoordinator, and the NSManagedObjectContext.

Symbols

Creating an NSPersistentContainer Object

init(name: String)

Initializes a persistent container with the given name.

init(name: String, managedObjectModel: NSManagedObjectModel)

Initializes a persistent container with the given name and model.

Configuring and Loading the Persistent Container

var persistentStoreDescriptions: [NSPersistentStoreDescription]

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

func loadPersistentStores(completionHandler: (NSPersistentStoreDescription, Error?) -> Void)

Instructs the persistent container to load the persistent stores.

Accessing the Managed Object Context(s)

func newBackgroundContext()

Creates a private managed object context.

func performBackgroundTask((NSManagedObjectContext) -> Void)

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

var viewContext: NSManagedObjectContext

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

Configuring the Persistent Store Location

class func defaultDirectoryURL()

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

Accessing Parts of the Container

var managedObjectModel: NSManagedObjectModel

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

var name: String

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

var persistentStoreCoordinator: NSPersistentStoreCoordinator

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

Relationships

Inherits From

Conforms To