4
在WWDC2016苹果公司推出NSPersistentContainer
为iOS10NSPersistentContainer等效NSPersistentStoreCoordinator.addPersistentStore ofType和期权
的NSPersistentContainer类是负责加载数据模型,创建一个管理对象模型,并用它来创建的NSPersistentStoreCoordinator。
它的初始化是很容易的:
let container = NSPersistentContainer(name: "myContainerName")
container.loadPersistentStores(completionHandler: { /* ... handles the error ... */ })
在我们成立了
NSPersistentStoreCoordinator
使用添加特别是PersistentStore与 “ofType” 和 “storeOptions”
let psc = NSPersistentStoreCoordinator(managedObjectModel: mom)
psc.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storeURL, options: [NSPersistentStoreFileProtectionKey:FileProtectionType.complete, NSMigratePersistentStoresAutomaticallyOption: true] as [NSObject : AnyObject])
的CoreData堆栈创建
以前在这种情况下,
NSSQLiteStoreType
对于的类型参数
和
[NSPersistentStoreFileProtectionKey:FileProtectionType.complete, NSMigratePersistentStoresAutomaticallyOption: true]
为选项参数
我如何设置这种使用NSPersistentContainer
东西?