Gio*_*zzi 6 core-data ios swift3 ios10
在WWDC2016上Apple引入NSPersistentContainer了iOS10
该NSPersistentContainer类是负责加载数据模型,创建一个管理对象模型,并使用它来创建的NSPersistentStoreCoordinator.
它的初始化非常简单:
let container = NSPersistentContainer(name: "myContainerName")
container.loadPersistentStores(completionHandler: { /* ... handles the error ... */ })
Run Code Online (Sandbox Code Playgroud)
以前在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])
Run Code Online (Sandbox Code Playgroud)
在这种情况下使用
NSSQLiteStoreTypefor ofType 参数
和
[NSPersistentStoreFileProtectionKey:FileProtectionType.complete, NSMigratePersistentStoresAutomaticallyOption: true]
for options 参数
如何配置这种东西NSPersistentContainer?
Har*_*nda 11
let description = NSPersistentStoreDescription()
description.shouldInferMappingModelAutomatically = true
description.shouldMigrateStoreAutomatically = true
description.setOption(FileProtectionType.complete, forKey: NSPersistentStoreFileProtectionKey)
container.persistentStoreDescriptions = [description]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1366 次 |
| 最近记录: |