arn*_*app 4 core-data nsmanagedobject nsmanagedobjectcontext ios
我正在寻找一种方法来跟踪NSManagedObject的属性更改.
目前我使用NSNotifactionCenter来查看我的managedobjectcontext的更改:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDataModelChange:) name:NSManagedObjectContextObjectsDidChangeNotification object:self.managedObjectContext];
Run Code Online (Sandbox Code Playgroud)
它会触发handleDataModelChange Methode,如下所示:
- (void)handleDataModelChange:(NSNotification *)note
{
NSSet *updatedObjects = [[note userInfo] objectForKey:NSUpdatedObjectsKey];
if (updatedObjects.count > 0) {
for (NSManagedObject *obj in updatedObjects.allObjects) {
NSLog(@"Object updated: %@ with values:",obj.entity.name);
NSDictionary *theAttributes = [self getAllAttributesOf:obj];
for (NSString *attributeName in theAttributes) {
NSLog(@"Name: %@ : %@",attributeName,[obj valueForKey:attributeName]);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果对象发生更改,则会记录该对象的新属性.如何获得获取旧属性值的方法?
返回一个字典,其中包含自上次获取或保存接收器以来已更改的持久属性的键和(新)值.
返回一个字典,其中包含自上次发布以来已更改的持久属性的键和旧值NSManagedObjectContextObjectsDidChangeNotification.
| 归档时间: |
|
| 查看次数: |
2070 次 |
| 最近记录: |