代码之家  ›  专栏  ›  技术社区  ›  Sidney Liu

Xcode 9中的Swift 4-如何轻量级核心数据迁移

  •  0
  • Sidney Liu  · 技术社区  · 8 年前

    我的核心数据将再更新一个属性,为了避免崩溃,我首先添加了一个新的模型版本,而且:

    关于这个问题的关键是改变:

    coordinator!.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
    

    选项:代码中无

    options:[NSMigratePersistentStoresAutomaticallyOption:true, NSInferMappingModelAutomaticallyOption: true]
    

    但在我 应用委托.swift ,我找不到任何 持续存储协调员 ,那么我可以在我的版本中迁移coredata吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Gulshan Kumar    7 年前
    You can achieve like this:
    
    let container = NSPersistentContainer(name: "YourDbModelName")
    let description = NSPersistentStoreDescription() 
    description.shouldMigrateStoreAutomatically = true 
    description.shouldInferMappingModelAutomatically = true 
    container.persistentStoreDescriptions = [description]
    
    推荐文章