I'm running into a crash issue while developing an iPhone app with Core Data.
The app syncs data with a webservice on a background thread.
When the app first launches, the existing data in the Core Data DB will be displayed to the user in a UITableView, while a background thread is kicked off the grab the latest data from the web service API. Lets call the core data models User and Items, just for discussion purposes with a User having many items. The items are what is displayed in the UITableView.
When the API results come back, the users existing Item records are deleted from Core data and the new set of Item records is inserted into Core Data. Once all items are parsed, a message is sent back to the main thread to merge in the core data changes and refetch the data from CD.
However, I keep crashing in my configure table cell routine, and I'm sure its because of out of scope objects. Meaning, the main thread is trying to display objects from Core Data, while the background thread is deleting those same objects from Core data and replacing them with new ones.
What is the best way to handle these kind of conflicts? Do I have to put in some kind of mechanism to not kick off the background thread updating until the main view has loaded/displayed all its data? If so, how do I accomplish this? Can I still keep my same methodology and just handle the deletion of displayed items better?