NSManagedObjectContextObjectsDidChangeNotification userInfo字典 [英] NSManagedObjectContextObjectsDidChangeNotification userInfo Dictionary
问题描述
我在我的应用程序中使用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?
推荐答案
查看文档 NSManagedObject
为您提供答案。
通知中有三个实例方法
A notification has three instance methods one of which is the -userInfo
method which returns the userInfo dictionary
.
看起来您的syncKVO:方法不正确;通知处理程序应将通知对象作为参数。
It looks like your syncKVO: method is incorrect; notification handlers should take the notification object as a parameter.
文档显示此字典,您可以使用类似这样的东西来获得您可能需要的:
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字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!