简体   繁体   中英

iPhone: Core Data: Updating a pre-filled database in future app versions

I am creating an app with a database of information that needs to be pre-filled. This data will change in future versions. In the same database, I also need to store user editable information since that user edited data directly relates to the pre-filled data.

My question is, if I'm pre-filling the database by creating a duplicate data model in a second app and copying over the core data file before release, how would I handle updates to that data in future versions of the app without destroying the user's existing data? Do the core data migration methods handle this, or must I write custom methods to programatically handle the merge at first app launch?

Depending on your data model, you can create two separate persistent files, one writable and one read only. You can then add both files to the NSPersistentStoreCoordinator and reach both of them together. You can then replace the read only file on future upgrades.

However this depends on how intertwined the two halves of the data are. If they are too tightly coupled then you will most likely have to do it the hard way; on future upgrades, purge the old data and copy the new objects over one by one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM