What is the most efficient way to sync Core Data with JSON API What is the most efficient way to sync Core Data with JSON API json json

What is the most efficient way to sync Core Data with JSON API


This could be ok, but I think you should apply the Find-or-Create pattern suggested in Apple doc. See here for a deep explanation Efficiently Importing Data (In particular see Implementing Find-or-Create Efficiently).

The overall idea is quite simple. Having two arrays of objects (the one you retrieve from Core Data and the one you retrieve from the service) that are ordered (by apiID and id resp.).

Obviously if there are a lot of data, I really suggest to perform operations in background. Remember that each thread needs to rely on its NSManagedObjectContext. Otherwise take advantage of new queue mechanism provided by iOS 5 API.

For the sake of completeness, I also suggest to read RayWenderlich tutorial How To Synchronize Core Data with a Web Service Part 1 and 2. It's very interesting.

Hope that helps.