I have successfully launched 1st version of my App with MyProject.xcdatamodel
. Now my 2nd version is under development and I created new model version named MyProject2.xcdatamodel
based on MyProject.xcdatamodel
and set it to Current
. I have enabled light-weight migration as following in my AppDelegate
:
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "MyProject")
// Support for light-weight migration
/*-------------------------------------------------------*/
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
}()
After doing this, I first installed my old version, and then installed new version on top of old. While launching new version, there is no data found from one of my database table of old model which I did not have touch. If I remove those 4 lines of migration, it is getting data.
What may be the reason? Is there anything wrong I am doing for light-weight migration?
You need to specify the URL for the location of the actual model's database location.