iPhone and Core Data: how to retain user-entered data between updates?

前端 未结 3 1468
滥情空心
滥情空心 2021-02-10 11:43

Consider an iPhone application that is a catalogue of animals. The application should allow the user to add custom information for each animal -- let\'s say a rating (on a scale

3条回答
  •  鱼传尺愫
    2021-02-10 12:10

    The way I'm doing this is: ship a database of the static stuff as part of your app bundle. On app launch, check if there is a database file in Documents. If not, copy the one from the app bundle to Documents. Then open the database from Documents: this is the only one you read from and edit.

    When an upgrade has happened, the new static content will need to be merged with the user's editable database. Each static item (Animal, in your case) has a field called factoryID, which is a unique identifier. On the first launch after an update, load the database from the app bundle, and iterate through each Animal. For each one, find the appropriate record in the working database, and update any fields as necessary.

    There may be a quicker solution, but since the upgrade process doesn't happen too often then the time taken shouldn't be too problematic.

提交回复
热议问题