本文介绍了NSManagedObjectContextObjectsDidChangeNotification userInfo字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序中使用NSManagedObjectContextObjectsDidChangeNotification通知,我已经现在如何使用它。因为我使用下面的代码添加观察者...
I am using the NSManagedObjectContextObjectsDidChangeNotification notfication in my app, I already now how to use it. As I have used the below code to add the observer …
- (void) awakeFromNib {
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(syncKVO:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:nil];
}
- (void)syncKVO:(id)sender {
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self
name:NSManagedObjectContextObjectsDidChangeNotification
object:nil];
// Do stuff.
[nc addObserver:self
selector:@selector(syncKVO:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:nil];
}
但我想检查userInfo字典
But I would like to check the userInfo dictionary to make sure the method actually has to be triggered, How would I do this?
推荐答案
查看显示此字典,您可以使用类似这样的东西来获得您可能需要的:
The documentation for the notification you are looking for shows the keys that are in this dictionary for this notification and you can use something like this to get what you might need:
- (void)syncKVO:(NSNotification *)notification {
NSDictionary *userInfoDictionary = [notification userInfo];
NSSet *deletedObjects = [userInfoDictionary objectForKey:NSDeletedObjectsKey];
// do what you want with the deleted objects
}
这篇关于NSManagedObjectContextObjectsDidChangeNotification userInfo字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!