Here is my problem:
- I want to use core data – speed and connectivity issues to build my IOS app. The data stored in core data is coming from a SQLServer database which I can access through a yet-to-be-defined web service.
- Any changes to the data stored in core data needs to be synchronized with the SQLServer via a web service. In addition, I need to buffer changes that don’t get synchronized because of connectivity issues.
- I also need to update core data with any changes that have occured on the server. This could happen on a schedule set in user preferences.
Solutions I’ve Explored:
- Using
NSIncrementalStoreclass (new in IOS 5). I’m very confused on what this does exactly but it sounds promising. From what I can tell, you subclassNSIncrementalStorewhich allows you to intercept the regular core data API calls. I could then pass on the the information to core data as well as sync it with the external database via a web service. I could be completely wrong. But assuming I’m right, how would I sync deltas if the connection to the internet is down? AFIncrementalStore– This is a subclass off ofNSIncrementalStoreusingAFNetworkingto do the web services piece.RestKit– I’m a little concerned on how active this API is and it seems to be going through a transition to block functionality. Has anyone used this extensively?
I’m leaning towards AFIncrementalStore since this is using (what seems to be) a more standard approach. The problem is, I could be completely off on what NSIncrementalStore really is.
A link to some sample code or tutorial would be great!
My solution to this was to store two copies of the data set in a CoreData database. One represents the last-known server state and is immutable. The other is edited by the user.
When it is time to sync changes, the app creates a diff between the edited and immutable copies of the data. The app sends the diff to a web service which applies the diff to its own copy of the data. It replies with a full copy of the data set, which the app overwrites onto both of its copies of the data.
The advantages are:
The disadvantages are:
Here are some of the considerations I had when coming up with the strategy:
The closest thing I’ve heard of to out-of-the-box support to do anything remotely like this is the new iCloud/CoreData syncing system in iOS6, which automatically transmits entities from a CoreData database to iCloud when they change. However, that means you have to use iCloud.
EDIT: This is very late, I know, but here’s a class that is capable of producing a diff between two NSManagedObject instances.
There’s more information about what it does, how it does it and its limitations/assumptions here:
http://simianzombie.com/?p=2379