Re: Stupid objective-c question
Re: Stupid objective-c question
- Subject: Re: Stupid objective-c question
- From: Uli Kusterer <email@hidden>
- Date: Sat, 24 Sep 2016 04:41:10 +0200
> On 22 Sep 2016, at 19:53, Quincey Morris <email@hidden> wrote:
>
> 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.
Or it could be done like other places in Cocoa (was it NSTrackingArea? Or the event monitors?), where you get an "id" return value back (some unknown object) that represents your registration and that you keep around and pass to the remove call to specify which registration to unregister.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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