Manufacturer Consumer Edition with Master Data

I have a Core Data application. In the producer thread, I retrieve data from the web service and save it in my object and save the call. My consumer object is a table view controller that displays the same thing. However, the application crashes and I get NSFetchedResultsController Error: expected to find the object (object: FeedEntry; id: 0xf46f40; data :) in the (null) section to delete

on the console. When I debug it, everything works fine. Therefore, I realized that this is like a race problem.

How is this problem solved? What is the best way to create a producer-consumer application with master data?

+6
iphone cocoa-touch cocoa core-data
source share
2 answers

If you are targeting Leopard or later, Apple has simplified the setup.

In the stream of your manufacturer, create MOCs with the same PSC as the MOCs in your main stream. You can pull objects from your web service in this thread, create new objects and save them as usual.

In your consumer chain, add a controller as an observer for NSManagedObjectContextDidSaveNotification. Your callback should look something like this:

- (void) managedObjectContextDidSave:(NSNotification *)notification { NSManagedObjectContext *managedObjectContext = [notification object]; if(managedObjectContext != self.managedObjectContext) [self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification]; } 

Thus, objects stored in the producerโ€™s stream will automatically be drawn into your consumer stream.

+16
source share

Master data is generally not thread safe. My preference would be to do minimal work on the background thread and transfer the data needed to create the Core Data objects to the main stream after you retrieve it from your web service. However, check out this document . There are some strategies for using Core Data over streams if you need to.

0
source share

All Articles