简体   繁体   中英

How to update the Pre-Populated CoreData SQLite file?

I know I can set a Pre-Populated SQLite file as CoreData persist file. But When I update my app version, and the Pre-Populated Data need be updated, I wonder if there has another way to do that except CRUD the new Pre-Populated data by codes after the new version launch.

您可以在persistentStoreCoordinator中选择预先填充的sqlite文件作为源文件,但是请记住,如果更新数据,则用户生成的内容将丢失...

In one of my project I have also faced a similar problem. My approach was that.

  1. Create 2 configuration in Core Data. One for static data and second for dynamic data.

  2. While configuring your persistantCordinator set two separate SQLite files corresponding CoreData configuration.

  3. There is not extrac coding effort other than setting up two separate DB in persistantCordinator level. Everything else will be managed by CoreData like. Reading, Writing etc.

  4. For static database keep a DATABASE version of your own. When your static data changed increase this database version and in App launch check the existing database version with this new version. If new version is greater copy and replace the existing static database.

With this approach you have the following benefits.

  1. You wont lose your dynamic data.

  2. You need to change the static database only when there is a change in static data.

Hope this helps.

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