Re: Receiver type for instance message is a forward declaration
Re: Receiver type for instance message is a forward declaration
- Subject: Re: Receiver type for instance message is a forward declaration
- From: Quincey Morris <email@hidden>
- Date: Tue, 10 May 2016 16:20:59 -0700
- Feedback-id: 167118m:167118agrif8a:167118sbz7l15ghZ:SMTPCORP
On May 10, 2016, at 16:11 , Jens Alfke <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden