我有一个 NSManagedObject,其中包含一个日期列和一个可转换列(一个 NSDictionary)。日期列和可转换列都在其自己的上下文中的后台线程上更新,然后合并到主线程的上下文中。尽管日期列正在更新并正确保存,但可转换列没有。可转换列正在以这种方式更新:
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();
}
在 mergeChanges: 我有以下内容:
- (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];
}
请帮忙。