gpt4 book ai didi

ios - NSPersistentContainer 等效于 NSPersistentStoreCoordinator.addPersistentStore ofType 和选项

转载 作者:可可西里 更新时间:2023-11-01 03:39:36 27 4
gpt4 key购买 nike

在 WWDC2016 上,Apple 推出了适用于 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 for ofType 参数

[NSPersistentStoreFileProtectionKey:FileProtectionType.complete, NSMigratePersistentStoresAutomaticallyOption: true]对于选项参数

如何使用 NSPersistentContainer 配置此类内容?

最佳答案

let description = NSPersistentStoreDescription()
description.shouldInferMappingModelAutomatically = true
description.shouldMigrateStoreAutomatically = true
description.setOption(FileProtectionType.complete, forKey: NSPersistentStoreFileProtectionKey)
container.persistentStoreDescriptions = [description]

关于ios - NSPersistentContainer 等效于 NSPersistentStoreCoordinator.addPersistentStore ofType 和选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42693394/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com