views:

45

answers:

1

Hoping to get some clear advice on this one.

I want to push updates to my app when it is live. I plan to do this by modifying the sqlite that ships with the app and then have the app download it. Easy.

I haven't worked out how actually get the app to see the new data though.. I can overwrite the sqlite in the documents directory, but the app has to be restarted for the new data to be picked up - no good. As a first step I don't mind if modifications to it are lost, but I am really looking for a way to keep any modifications to data, and add/remove entries based on the new sqlite. It will be the entire data-set rather than just the changes.

I am going down this path as the data is quite complex, but manageable through a desktop app based on same core-data model.

Is there a common way, or a way at all to achieve this?

Thanks.

+1  A: 

There is no simple way to completely merge to two Core Data stores SQL or other wise.

Maintaining the integrity of the object graph requires that new data be inserted into the existing store via a context using the same model as that used to create the store. In other words, batch adding new data to the store is the same logical process as adding it one piece at a time from UI. You insert NSManagedObject instances, populate them, set their relationships and save them.

In theory, you could write great gobs of code to merge the old and new SQL databases into a new SQL store that Core Data could read. However, that is complex, unsupported and likely to break when Apple revs something in the future.

I would recommend having the app itself download the data piecemeal from the server and then insert the new data into the existing store. It's trivial to send data using something like JSON. Alternatively, you could download a new store, add it to the existing persistent store coordinator and then create clones the new objects in the old store. Then remove the downloaded store from the coordinator and delete the downloaded store file.

TechZen
Thanks TechZen, I was trying to avoid having to write a webapp (albeit simple) to feed the iPhone app. I am going down the JSON path as dealing with multiple stores is not working out.
michael