I'm using NSNotificationCenter
to send custom notifications in a document-based app.
A document-based app can have many open documents. Ideally, I would like the the document and its children to receive only the notifications created within the document or its children. In other words, a document should receive only the notifications that the same document generates.
At first I thought I could use the notificationSender
parameter of addObserver:selector:name:object:
but then I realised that I don't always know which object will send the notification.
Do I have to check if I'm in the right document for every custom notification? Is there a better way to do this?
I think that your approach works if you use the main document as notificationSender
argument for both addObserver:selector:name:object:
and postNotificationName:object:
.