> On 22 Sep 2016, at 19:53, Quincey Morris > <quinceymor...@rivergatesoftware.com> wrote: > > On Sep 22, 2016, at 03:16 , Gabriel Zachmann <z...@tu-clausthal.de> 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 (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