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

Ios 从MagicalRecord到NSPersistentContainer。如何保存数据?,ios,core-data,magicalrecord,Ios,Core Data,Magicalrecord,在当前的live App Store应用程序上,我正在使用MagicalRecord设置我的核心数据。当我面临一些并发性问题时,我四处寻找解决方案。我意识到,自从iOS 10推出以来,核心数据已经简化,我可以直接使用它,而无需神奇的记录 魔法唱片设置 lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "Model") contain

在当前的live App Store应用程序上,我正在使用MagicalRecord设置我的核心数据。当我面临一些并发性问题时,我四处寻找解决方案。我意识到,自从iOS 10推出以来,核心数据已经简化,我可以直接使用它,而无需神奇的记录

魔法唱片设置

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
}()
使用最新的存储库和迦太基,我使用下面的行来设置核心数据

    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
}()
问题

这就像建立一个新的数据库,我无法访问存储在神奇记录设置中的数据


我试图查看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
}()