On May 10, 2016, at 16:11 , Jens Alfke <j...@mooseyard.com> wrote:
> 
> what goes wrong if it’s NULL

If anything else uses NULL, then your observation is not uniquely identified, 
which means that:

— you might respond to a notification registered by an ancestor class of your 
observer instance, breaking some of its functionality;

— *removing* the observer can remove the wrong observation.

Since there are believed to be a few cases where Cocoa registers its own 
observations in classes that apps will actually subclass, and Cocoa uses NULL 
for such contexts, apps should avoid NULL. In addition, for uniqueness within 
the app’s code, it’s easiest to use something other than NULL that’s known to 
be unique to the current compilation unit (usually).

This is also why a version of ‘removeObserver’ that takes a ‘context’ parameter 
was retrofitted, several OS X versions ago.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to