How to maintain data in an SQLite Database on an iPhone at a version update of the application?

后端 未结 2 1131
北荒
北荒 2021-01-04 13:32

I have an SQLite database in the first version of my iPhone application (which is on the app store). Now I want to roll out the second version of the application, which also

2条回答
  •  礼貌的吻别
    2021-01-04 14:11

    The answer is: implement versioning in your app from the very start :-)

    In this case, you can consider an app with no version information to be version 1. What I would do is store the version of the database somewhere (probably inside the database itself). When the database is opened, check its version against what version the app expects, then make any schema changes as needed and update the stored version number.

    If you haven't copied the database to the app's Documents directory, then this is all moot because it would be read only anyway. Otherwise, the contents of the Documents directory are preserved between updates.

    To test the update, just start with a fresh copy of the previous version on your device. Then install the new one (build and run will do just fine). You do keep old versions of your app, right?

提交回复
热议问题