swift - iCloud 核心数据版本迁移

标签 swift core-data icloud core-data-migration nspersistentcloudkitcontainer

我在生产中有一个 Core Data 应用程序,我想向现有实体添加属性。经过研究,我发现这是一个“轻量级迁移”,只需要在加载持久存储:

let container = NSPersistentCloudKitContainer(name: "app")

guard let description = container.persistentStoreDescriptions.first else { fatalError("Container not available") }

//For migration VVV

description.setOption(true as NSNumber, forKey: NSMigratePersistentStoresAutomaticallyOption)
description.setOption(true as NSNumber, forKey: NSInferMappingModelAutomaticallyOption)

//End of migration additions ^^^

container.loadPersistentStores(completionHandler: { (storeDescription, error) in
     if let error = error as NSError? {
          fatalError("Store loading failure")
     }
}

虽然这看起来很容易解决,但我只有两个问题无法在其他任何地方找到答案:

<强>1。对于从现在起更新其应用版本的任何人,我能否为应用的所有 future 版本保留这两个新的迁移选项?

<强>2。由于我使用的是 NSPersistentCloudKitContainer,因此在向 CloudKit Dashboard 发布新数据模型时,用户当前的应用版本是否应该包含这两个迁移选项?恐怕如果 CloudKit 数据模型与他们的应用程序版本不同,它会在同步他们的项目时崩溃他们的应用程序

非常感谢对此的任何帮助!更改数据模型总是一种可怕的经历,而且我从来没有做对,而且总是导致人们的应用程序崩溃。非常感谢您提供的任何帮助。

最佳答案

关于swift - iCloud 核心数据版本迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67642437/

相关文章:

ios - 使用 self.navigationController.hidesBarsOnSwipe = true 隐藏导航栏,永久隐藏

ios - 无法以编程方式重置 UINavigationController.presentedViewController

ios - iCloud 可以用来在用户之间交换数据吗?

ios - 其值在 block 内赋值的引用变量

Swift IOS 10 Firebase 推送通知

uitableview - searchDisplayController、UITableView、核心数据和 Swift

swift - 核心数据,如何从关系集合(NSSet)中删除一个元素

iphone,在不执行提取的情况下获取对象计数?

cocoa - 用 "iCloud"和 "On my mac"打开对话框?

iphone - 如何解释 document.state == 12 (iCloud)