App install, with a change in the Core Data model

70 views Asked by At

It is possible to perform Lightweight Migrations with core data, as well as more advanced kind of migrations. But there are also cases where there is no need to spend time worrying about migration; for example when the DB is read only or when the data can be recreated automatically. In such a case it would be good to display a message to the user, when the app is installed. In case an old version of the app, with an old data model is present on the device, a message would tell the user to remove the old version of the app first and then install the new version.

How can I do that in my iOS app?

1

There are 1 answers

1
Jasper Chan On

NSPersistentStoreCoordinator has a method called metadataForPersistentStoreOfType:URL:error: that will allow you to create your source coredata's metadata. With this information in conjunction with NSManagedObjectModel's isConfiguration:compatibleWithStoreMetaData, you can figure out whether or not a migration is necessary.