gpt4 book ai didi

ios - 从 MagicalRecord 到 NSPersistentContainer。如何保存数据?

转载 作者:行者123 更新时间:2023-12-01 15:50:22 27 4
gpt4 key购买 nike

在当前运行的 App Store 应用程序中,我使用 MagicalRecord 来设置我的核心数据。当我遇到并发问题时,我四处寻找解决方案。我意识到自从引入 iOS 10 以来,Core Data 得到了简化,我可以直接使用它而无需 Magical Record。

神奇的记录设置

使用最新的存储库和 carthage,我使用以下行来设置核心数据。

    MagicalRecord.setupCoreDataStack(withAutoMigratingSqliteStoreNamed: "Model")

NSPersistentContainer 设置

lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "Model")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()

问题

这就像设置一个新数据库,我无法访问使用 Magical Record 设置存储的数据。

我试图查看 MagicalRecord 是否对使用的名称进行了任何更改,但看起来没有。有谁知道如何进行转换并仍然能够访问我的旧数据。

最佳答案

您可能只需要更正商店 URL,因为它位于非标准位置。

lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "Model")

// Change from the default store location
let url = .... where is your database?
let description = NSPersistentStoreDescription(url: url)
container.persistentStoreDescriptions = [description]

container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()

关于ios - 从 MagicalRecord 到 NSPersistentContainer。如何保存数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44820118/

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