Iphone mergeChangesFromContextDidSaveNotification删除记录
我试图在后台线程上更新CoreData中的记录。我正在根据文档为每个线程创建NSManagedObjectContext。我还注册了数据保存时的通知。但是,mergeChangesFromContextDidSaveNotification正在删除条目,而不是更新条目Iphone mergeChangesFromContextDidSaveNotification删除记录,iphone,core-data,Iphone,Core Data,我试图在后台线程上更新CoreData中的记录。我正在根据文档为每个线程创建NSManagedObjectContext。我还注册了数据保存时的通知。但是,mergeChangesFromContextDidSaveNotification正在删除条目,而不是更新条目 //Notification callback - (void)_managedObjectContextDidSave:(NSNotification *)notification { dispatch_async(di
//Notification callback
- (void)_managedObjectContextDidSave:(NSNotification *)notification
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
});
}
//per thread managed object context
- (NSManagedObjectContext *)managedObjectContext
{
if ([[[NSThread currentThread] threadDictionary] objectForKey:GVControllerManagedObjectContextKey] == nil) {
NSPersistentStoreCoordinator *coordinator = self._persistentStoreCoordinator;
if (coordinator != nil) {
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:coordinator];
if (![NSThread isMainThread]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_managedObjectContextDidSave:) name:NSManagedObjectContextDidSaveNotification object:managedObjectContext];
}
[[[NSThread currentThread] threadDictionary] setObject:managedObjectContext forKey:GVControllerManagedObjectContextKey];
[managedObjectContext release];
}
}
return [[[NSThread currentThread] threadDictionary] objectForKey:GVControllerManagedObjectContextKey];
}
看起来我使用的是另一个线程中的托管对象,该线程被添加为我正在更新的对象的属性