【发布时间】:2017-07-30 07:45:17
【问题描述】:
苹果在 WWDC2016 上为 iOS10 推出NSPersistentContainer
NSPersistentContainer 类负责加载数据模型,创建托管对象模型,并使用它来创建 NSPersistentStoreCoordinator。
它的初始化真的很简单:
let container = NSPersistentContainer(name: "myContainerName")
container.loadPersistentStores(completionHandler: { /* ... handles the error ... */ })
之前在 CoreData 堆栈创建中,我们设置了 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])
在这种情况下使用
NSSQLiteStoreType 用于 ofType 参数
和
[NSPersistentStoreFileProtectionKey:FileProtectionType.complete, NSMigratePersistentStoresAutomaticallyOption: true]
对于选项参数
如何使用NSPersistentContainer 配置这种东西?
【问题讨论】:
标签: ios core-data swift3 ios10