//设置通知
[[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(dataChanged:) name:NSManagedobjectContextDidSaveNotification object:context];
//后来
- (void)dataChanged:(NSNotification *)notification{ NSDictionary *info = notification.userInfo; NSSet *insertedobjects = [info objectForKey:NSInsertedobjectsKey]; NSSet *deletedobjects = [info objectForKey:NSDeletedobjectsKey]; NSSet *updatedobjects = [info objectForKey:NSUpdatedobjectsKey];
有没有从更新对象确定哪些字段实际上改变?
谢谢,
迈克尔
解决方法
以下应该做的诀窍,但您将需要使用NSManagedobjectContextwillSaveNotification,并通过用于保存对象的相同的NSManagedobjectContext访问更新的对象.
for(NSManagedobject *obj in updatedobjects){ NSDictionary *changes = [obj changedValues]; // Now process the changes as you need }
参见评论中的讨论.