Re: Stupid objective-c question
Re: Stupid objective-c question
- Subject: Re: Stupid objective-c question
- From: Quincey Morris <email@hidden>
- Date: Thu, 22 Sep 2016 10:53:11 -0700
- Feedback-id: 167118m:167118agrif8a:167118sS5zSm_QeE:SMTPCORP
On Sep 22, 2016, at 03:16 , Gabriel Zachmann <email@hidden> wrote:
>
> That makes me wonder: why isn't it possible to register several, different observers for the same thing?
> That way, I wouldn't need to care about observations I didn't create, would I?
Because the observer is an object. Your observation and a superclass observation come from the same object. Whether these are to be treated as different observations** cannot be determined automatically, hence the need for a “context”.
The reason it’s messy is that the observer/notification API is old and doesn’t follow modern API design practices. If this were being designed today, the “observeValueForKeyPath…” method would likely be replaced by a block/closure (similar to a completion handler) that’s passed as a parameter to the “addObserver…” call, and there wouldn’t be any contexts.
** That is, a superclass ‘addObserver’ may be in common code that’s used by all the subclasses, or it may be a private observation that’s separate from what subclasses use. Where the observation is created is insufficient to determine whether it’s an observation “you” created, or you “care about”.
_______________________________________________
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