At WWDC2016 Apple introduces NSPersistentContainer
for iOS10
The NSPersistentContainer class is in charge of loading the data model, creating a managed object model, and using it to create a NSPersistentStoreCoordinator.
Its initialization is really easy:
let container = NSPersistentContainer(name: "myContainerName")
container.loadPersistentStores(completionHandler: { /* ... handles the error ... */ })
Previously in the CoreData stack creation we set up the NSPersistentStoreCoordinator
adding a PersistentStore in particular with "ofType" and "storeOptions"
let psc = NSPersistentStoreCoordinator(managedObjectModel: mom)
psc.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storeURL, options: [NSPersistentStoreFileProtectionKey:FileProtectionType.complete, NSMigratePersistentStoresAutomaticallyOption: true] as [NSObject : AnyObject])
using in this case
NSSQLiteStoreType
for ofType parameter
and
[NSPersistentStoreFileProtectionKey:FileProtectionType.complete, NSMigratePersistentStoresAutomaticallyOption: true]
for options parameter
How can I configure this kind of stuff using NSPersistentContainer
?