Is it possible to limit targets of NSNotification?
I want to send a NSNotification to a specific object (to self), without having other objects see / respond to it.
开发者_如何学GoIs this possible without editing the other objects?
Well, if you really must use the same notification name, one thought would be to put the self pointer into userInfo. Then on the observer side, if you don't see a self pointer then you assume it's a general notification, not specific to any particular observer.
If you do see a self pointer, you compare it to yourself to decide if to handle it. I'm not sure it satisfies your constraint of "no edits", but it does at least satisfy the requirement that the superclass code doesn't need to know of all the possible subclasses.
精彩评论