views:

56

answers:

1

I'm in the middle of developing a companion iPhone app for an existing web application.

To give a brief overview, the iPhone app is a tab bar based application with each tab containing navigation controllers.

At the moment the iPhone app is downloading data from the web app in a synchronous mode on the main thread that, of course, ties up the UI. Both tabs in the tab bar have the main view of their nav controller as a UITableView that is using a FetchedResultsController to handle displaying the appropriate data from Core Data.

Now that I know all my data transfer and processing from the API on the web app is working, I want to move the data syncing off the main thread and into the background where it should be.

My question is how do I properly handle this in the background threads and then also properly notify the main thread where the FRC lives that it needs to update it's view? I have a SyncController that is doing the data retrieval and associated Core Data processing which can continue to be used, but how should I go about letting the main thread update it's views with the new Core Data contents?

Due to the bug with doing mass updates into core data while using an FRC with multiple sections, I have just been setting a mass update flag in a Config singleton instance, but I don't believe I can still use this same technique as well on a background thread, correct?

+2  A: 

You can create a separate NSManagedObjectContext to use during your syncing operation. Check out the TopSongs sample project. It uses CD and NSOperation to perform the refresh on a separate thread. When you save in your syncing context notifications will be posted which you can use to signal that you need to update your view. Register for NSManagedObjectContextDidSaveNotification in your viewController that has the FRC.

falconcreek