- Core Data
NSPersistent is supported in iOS 10.0+ and macOS 10.12+. If you’re deploying to an earlier target, you need to manually instantiate an
NSPersistent, and at least one
Create a Managed Object Model
To instantiate an
NSManaged, you pass in a URL that points to the compiled version of the
.xcdatamodeld file. This
.momd file is typically part of your app bundle.
Create a Persistent Store Coordinator
Next, you pass the loaded model into the
NSPersistent initializer, to create a store coordinator associated with the model.
Add a Persistent Store
If you want Core Data to persist your data model to disk, tell the store coordinator where the file will reside and what format to use.
There are advantages and disadvantages to each of the available store types. Refer to the
NSPersistent documentation for details on each store type.
Create a Managed Object Context
NSManaged, and set its store coordinator property.
The bulk of your app’s interaction with Core Data will be with this context. Pass this context by reference to your user interface. See Pass a Persistent Container Reference to a View Controller.