我有一个NSManagedObject,它包含一个日期列和一个Transformable列(一个NSDictionary)。 date列和transformable列都在其自己的上下文中的后台线程上更新,然后合并到主线程的上下文中。虽然日期列正在更新并正确保存,但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];
}
请帮忙。
答案 0 :(得分:0)
问题必须在mergeChangesFromContextDidSaveNotification
方法中。检查是否正在调用此方法。如果是,问题就在那里。