核心数据轻量级迁移-添加版本时使xcode崩溃

时间:2018-12-24 09:21:12

标签: core-data

我的核心数据将再更新一个属性,为避免崩溃,我首先添加了一个新的模型版本,但由于我的应用程序委托者没有持久的协调器,因此在哪里可以将迁移选项设置为true

1 个答案:

答案 0 :(得分:0)

    lazy var persistentContainer: NSPersistentContainer = {

    let container = NSPersistentContainer(name: "Your Core data modeld name")
    let description = NSPersistentStoreDescription()
    description.shouldMigrateStoreAutomatically = true
    description.shouldInferMappingModelAutomatically = true
    container.persistentStoreDescriptions = [description]
    //--------------------------------------------------------//
    container.loadPersistentStores(completionHandler: { (storeDescription, error) in
        if let error = error as NSError? {
            fatalError("Unresolved error \(error), \(error.userInfo)")
        }
    })
    return container
}()