1

I have multiple instances of NSWindowController, who is registering for a notification to listen whenever edit happens.

Now when I edit something from one instance of windowcontroller, the notification gets posted and all the instances of that NSWindowcontroller listen to that notification,but I want only the instance which has updated its details to listen.

How can I achieve that?

subhash Amale
  • 325
  • 3
  • 4
  • 14

1 Answers1

2

As mentioned in the documentation for [NSNotificationCenter addObserver:selector:name:object:] method for parameter object:

The object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer. If you pass nil, the notification center doesn’t use a notification’s sender to decide whether to deliver it to the observer.

So just pass self as object.
E.G.

Registering for notifications:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(someSelector:)
                                                 name:@"SomeNotification"
                                               object:self]; // <- SELF!!

Posting notification:

[[NSNotificationCenter defaultCenter] postNotificationName:@"SomeNotification"
                                                            object:self //<- SELF!!
                                                          userInfo:nil];
arturdev
  • 10,884
  • 2
  • 39
  • 67