UIManagedDocument is a concrete subclass of
UIDocument that integrates with Core Data. When you initialize a managed document, you specify the URL for the document location. The document object then creates a Core Data stack to use to access the document’s persistent store using a Managed object model from the application’s main bundle. See Using Document Storage with iCloud in iCloud Programming Guide for Core Data for implementation strategies and troubleshooting steps.
- iOS 5.0+
UIManagedDocument performs all the basic set-up you need for Core Data, and in some cases you may use instances of
UIManagedDocument directly (without a need to subclass). You can supply configuration options for the creation of the coordinator using
persistentStoreOptions, and for the model using
modelConfiguration. You can also perform additional customization by creating a subclass of
Override persistentStoreName() to customize the name of the persistent store file inside the document’s file package.
managedObjectModelto customize creation of the managed object model.
You do this if, for example, your application supports multiple document types, each of which uses a different model. You want to ensure that the models are not merged for each document class.
persistentStoreType(forFileType:)to customize the type of persistent store used by a document.
configurePersistentStoreCoordinator(for:ofType:modelConfiguration:storeOptions:)to customize the loading or creation of a persistent store.
To enable your app to observe and handle errors in saving and validating a managed document, you must subclass the
UIManagedDocument class and override one or both of the following two inherited methods from the
Overriding is required because, otherwise, the only information your app receives on error is the
UIDocumentStateChanged notification, which does not contain a
userInfo dictionary and so does not convey specific error information.