My project has a need to cache on the iOS device data retrieved from a remote web service. The idea is the view controller will ask the cache for all the document objects it has, for example, and in the background will request a refresh from the web service, returning to the view controller any new document objects it received. I’m wondering whether it’s possible for the view controllers to use a NSFetchedResultsController that retrieves whatever objects matching the criteria it can find locally in the database, and also asynchronously asks for data refreshes from the web service in the background. In doing so, the NSFetchedResultsController would update the database and of course trigger the didChangeObject method of the FetchedResultsController delegate so the views can update accordingly. Does that sound reasonable? Do you have any suggestions for implementing such a thing?
Share
For our project, we ended up being able to simplify the problem quite a bit. However, on the journey of discovery, we came across NSIncrementalStore, which is just the ticket for problem posed in the question. It essentially gives you control over how and where CD persists data. Here’s a really nice post about it, and an easy-to-understand example. Admittedly there’s not a lot of doco around about it, but these posts really helped me get going.