Observing NSWindow properties breaks when a window's delegate is set

151 Views Asked by At

I'm observing the following notifications for a window:

  • NSWindowDidMoveNotification
  • NSWindowDidResizeNotification
  • NSWindowDidChangeScreenNotification

I register as an observer in my NSWindowController subclass using the following code:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(persistedWindowPropertiesDidChange:)
                                                 name:<Notification Name>
                                               object:self.window];

I observed behavior that I haven't experienced before and was wondering why it was occurring.

If the window's delegate property is set to nil, everything works as expected (notifications are observed). However, if the window's delegate is set to an object, passing self.window for the object parameter of -addObserver:selector:name:object: causes the selector to never be called. If nil is passed for the object parameter, the selector is called for all windows (expected behavior). Why does setting the delegate of the window break the filtering by object behavior of the notification center? This is occurring on 10.11.6.

Thanks for any insight!

0

There are 0 best solutions below