假设最新的应用程序发行版为版本20。到目前为止,有20次核心数据迁移,直到版本20。 例如:使用版本3的用户直接将其自动更新为版本20。
我想删除coredata堆栈,然后重建它。 但这解决了模型更新问题吗?表示版本3使用v3数据模型更新(xcdatamodel),版本20使用v20数据模型更新(xcdatamodel)。 如果我在用户自动将应用程序从版本3升级到20时使用以下代码删除并重建coredata,请执行以下操作: 那么它还会指向新的xcdatamodel版本吗?
var allstores : Array = self.storeContainer.persistentStoreCoordinator.persistentStores
for store in allstores{
// remove store file from coordinator
do {
try storeContainer.persistentStoreCoordinator.destroyPersistentStore(at: store.url!,ofType: NSSQLiteStoreType,options: nil)
} catch let error {
print("\(error.localizedDescription)")
}
}
然后重建。.
self.storeContainer.loadPersistentStores(completionHandler: { (nsPersistentStoreDescription,error) in
guard let error = error else {
return
}
fatalError(error.localizedDescription)
})