在CoreData保存之前识别哪些字段已经改变
//设置通知
[[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 }
请参阅评论中的讨论。