Skip to main content

Posts

Showing posts with the label nsmanagedobjectcontext

CoreData relationships are nil after mergeChangesFromContextDidSaveNotification

Having some truly strange behavior with Core Data on iOS. I have a NSManagedObjectContext for my main thread used to read data from a SQLLite persistent store and display it to the user. I also have background processes managed by an NSOperationQueue. These background processes create an NSMangedObjectContext, fetch data from remote servers, and persist that data to the local Core Data store. I have registered for NSManagedObjectContextDidSaveNotification and when I receive those notifications call mergeChangesFromContextDidSaveNotification on the main threads NSManagedObjectContext (passing the notification object as an argument). This is all very standard and the way that all the Core Data document suggest that you deal with multi-threading. Up until recently, I have always been inserting new objects into the data store and not modifying objects in the data store. This worked fine. After a background thread writes new data, the merge occurs, I send a notification to the UIControl