简体   繁体   中英

CoreData Update Database Leaving User Entries

First, Thank you for any help provided.

I have an iOS leveraging CoreData to retain various presentations, this data comes from a sqlite file and there is no server connection.

I will have to be able to provide App updates (via appstore), this update may add more data to the database. The tricky part is that it can not simply overwrite the current database, there are a few user tables that I will not like touched.

Please provide any information I should consider when accomplishing this or any links are greatly appreciated.

Thank you.

Given your app has no server connection, you will have to rely on shipping data within the updated application itself. I would recommend using a plist file or define your own xml or json structure. You can then read this data to create/update core data nsmanagedobjects.

It looks like someone in the past was using plist->coredata on SO

Would you have relationships between user created data and shipped data?

If not, you might go the route of connecting two stored to the persistent store coordinator. The shipped store would be read-only. The store with user created data would be read-write. You can use this approach, too, if you have relationships between shipped and user-created objects, but it's a lot more complicated, since CoreData doesn't manage cross-store relationships for you, and you'll need to write your own logic (doable, but not straight forward).

If you need to have relationships between shipped and user-created objects, you can still ship a CoreData store. When the app launches for the first time (no user-created objects), you copy the store to the Documents folder and user this store to create your CoreData stack. User created objects will be added to this store. Once you have new 'shipped' objects (ie a new store in the app-bundle), you'll have to manually migrate that stores data into the store that the user has changed. You'll have to be able to find (1) objects that need to be deleted (2) objects that need to be updated (changed) (3) objects that need to be added If you mark your shipped objects with a special flag such that you can tell if it's a user created object or a shipped one, that would be doable. You also have to have some sort of ID to be able to tell which objects in the new store correspond to which ones in the existing (old) store.

You do not need to go the route of using plists. In fact, I'd recommend against it. You can easily open two stores at the same time. Either to use both stored, or just to migrate objects from one store to the other store.

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