gpt4 book ai didi

ios - 核心数据迁移 : Changing Persistent Store ofType

转载 作者:可可西里 更新时间:2023-11-01 02:08:49 25 4
gpt4 key购买 nike

我真的需要帮助来改变核心数据结构。我已经使用现有数据库构建了我的应用程序,但现在我想使用 Seam cloudKit sync,我必须更改我的代码,但如果我这样做,我的应用程序将会崩溃!(删除并重新构建应用程序不是一种选择.. 正如我提到的,它已经有了它的数据结构)

NSPersistentStoreCoordinator 中,我使用了以下代码:

try coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: [NSMigratePersistentStoresAutomaticallyOption: true,NSInferMappingModelAutomaticallyOption: true])

现在我必须使用它:

try coordinator.addPersistentStore(ofType: SMStore.type, configurationName: nil, at: url, options: [NSMigratePersistentStoresAutomaticallyOption: true,NSInferMappingModelAutomaticallyOption: true]) as? SMStore

正如您注意到的,我必须将 ofType 从 NSSQLiteStoreType 更改为 SMStore.type

有什么办法吗?有人知道吗?我希望有人能提供帮助。

非常感谢。

最佳答案

为此,您可以使用 NSPersistentStoreCoordinator 方法 migratePersistentStore(_:to:options:withType:)。此方法将现有持久存储文件移动到新文件,并且可以更改持久存储类型。尽管名称中带有“迁移”,但它与模型版本迁移没有任何关系。在这种情况下,它将持久存储迁移到新文件。

您必须使用旧存储类型添加持久存储,然后迁移到新存储类型。

关于ios - 核心数据迁移 : Changing Persistent Store ofType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41674438/

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