Xcode 9中的SWIFT 4-如何实现轻量级核心数据迁移? [英] Swift 4 in Xcode 9 - How to lightweight Core Data migration?
本文介绍了Xcode 9中的SWIFT 4-如何实现轻量级核心数据迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的核心数据将再更新一个属性,为了避免崩溃,我首先添加了一个新的模型版本,而且:👇👇👇
这个问题最关键的是变化:
coordinator!.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
选项:在代码中为空
options:[NSMigratePersistentStoresAutomaticallyOption:true, NSInferMappingModelAutomaticallyOption: true]
但在我的appDelegate.swft中,我找不到任何"PersistentStoreColorator",所以我可以在我的版本中迁移CoreData吗?
推荐答案
You can achieve like this:
let container = NSPersistentContainer(name: "YourDbModelName")
let description = NSPersistentStoreDescription()
description.shouldMigrateStoreAutomatically = true
description.shouldInferMappingModelAutomatically = true
container.persistentStoreDescriptions = [description]
这篇关于Xcode 9中的SWIFT 4-如何实现轻量级核心数据迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文