添加使用块删除观察者

可以使用块来代替添加带选择器的观察者:

id testObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"TestNotification"
                                                                    object:nil 
                                                                     queue:nil 
                                                                usingBlock:^(NSNotification* notification) {
    NSDictionary *userInfo = notification.userInfo;
    MyObject *myObject = [userInfo objectForKey:@"someKey"];
}];

然后可以删除观察者:

[[NSNotificationCenter defaultCenter] removeObserver:testObserver 
                                                name:@"TestNotification"
                                              object:nil];