I have an NSManagedObject that contains a date column and a Transformable column (an NSDictionary). Both the date column and the transformable column are being updated on a background thread in its own context and then merged onto the context of the main thread. Though the date column is being updated and saved properly the Transformable column is not. The transformable column is being updated in this way:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(mergeChanges:) name:NSManagedObjectContextDidSaveNotification object:managedObjectContext];
NSMutableDictionary *newUserDataDictionary = [NSMutableDictionary dictionaryWithDictionary:object.userDataDictionary];
//Updated newUserDataDictionary here
object.date = calendarDay.date;
object.userDataDictionary = newUserDataDictionary;
if (![managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
In mergeChanges: I have the following:
- (void)mergeChanges:(NSNotification *)notification
{
AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
// Merge changes into the main context on the main thread
[delegate.managedObjectContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)
withObject:notification
waitUntilDone:YES];
}
Please help.
The problem must be in the
mergeChangesFromContextDidSaveNotification
method. Check if this method is being called. If yes, the problem resides there.