Mik*_*ike 13 core-data objective-c nsmanagedobjectcontext ios
//设置通知
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(dataChanged:)
name:NSManagedObjectContextDidSaveNotification
object:context];
Run Code Online (Sandbox Code Playgroud)
//后来
- (void)dataChanged:(NSNotification *)notification{
NSDictionary *info = notification.userInfo;
NSSet *insertedObjects = [info objectForKey:NSInsertedObjectsKey];
NSSet *deletedObjects = [info objectForKey:NSDeletedObjectsKey];
NSSet *updatedObjects = [info objectForKey:NSUpdatedObjectsKey];
Run Code Online (Sandbox Code Playgroud)
无论如何要从updatedObjects确定哪些字段实际更改了?
谢谢,迈克尔
Mas*_*aro 18
以下应该可以解决这个问题,但是您需要使用NSManagedObjectContextWillSaveNotification并通过用于保存对象的相同NSManagedObjectContext访问更新的对象.
for(NSManagedObject *obj in updatedObjects){
NSDictionary *changes = [obj changedValues];
// now process the changes as you need
}
Run Code Online (Sandbox Code Playgroud)
请参阅评论中的讨论.
归档时间: |
|
查看次数: |
3442 次 |
最近记录: |