Instance Method


Configures the receiver’s persistent store coordinator with the appropriate stores for a given URL.


func configurePersistentStoreCoordinator(for url: URL, ofType fileType: String, modelConfiguration configuration: String?, storeOptions: [String : Any]? = nil) throws



An URL that specifies the location of the document's store.


The document type.


The name of the managed object model configuration to use. (The managed object model is associated with the persistent store coordinator.) Pass nil if you do not want to specify a configuration.


Options for the store. See “Store Options” in NSPersistentStoreCoordinator for possible values.


If the method does not complete successfully, upon return contains an NSError object that describes the problem.

Return Value

true if the method completes successfully, otherwise false.


This method is invoked automatically when an existing document is opened. You override this method to customize creation of a persistent store for a given document or store type. You can retrieve the persistent store coordinator with the following code:

[[self managedObjectContext] persistentStoreCoordinator];

You can override this method to create the store to save to or load from (invoked from within the other NSDocument methods to read/write files), which gives developers the ability to load/save from/to different persistent store types (default type is XML).

See Also

Managing the Persistence Objects

var managedObjectContext: NSManagedObjectContext?

The managed object context for the document.

var managedObjectModel: NSManagedObjectModel?

The managed object model of the document.

func persistentStoreType(forFileType: String) -> String

Returns the type of persistent store associated with the specified file type.