简体   繁体   中英

Transformable attribute updated in background thread context not being saved when being merged into main thread context

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM