我有一个NSManagedObject,它包含一个日期列和一个可转换列(NSDictionary)。日期列和可转换列都是在后台线程自己的上下文中更新的,然后合并到主线程的上下文中。虽然日期列正在被正确更新和保存,但Transformable列却没有。可转换列以以下方式更新:
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];
}
请帮。
问题一定在mergeChangesFromContextDidSaveNotification
方法中。检查是否正在调用此方法。