On 23 Sep 2016, at 00:07, Quincey Morris <quinceymor...@rivergatesoftware.com> wrote: > > On Sep 22, 2016, at 15:45 , Gabriel Zachmann <z...@tu-clausthal.de> wrote: >> >> Sure, but an observation method is what would be called a "callback" in >> plain C. >> In C, I can have many different callbacks. >> I don't see why that should not be possible in Obj-C - I just would need a >> mechanism to add tell the system the names / function pointers to be >> registered as observers. > > It is of course possible in Obj-C. There are APIs that have a “didEnd” > selector, such as (deprecated) ‘[NSApplication > beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:]’. That’s > similar to the KVO notification method concept, except that you get to > specify a selector and a target object. Note, however, that such APIs tend to > have a context parameter, too**. > > But that’s because the KVO notification mechanism is a more ancient design > concept, where it likely seemed simple, adequate and flexible. I assume it > comes from NeXTStep days (late 80s or early 90s), not OS X 10.0 days (early > 2000s), although I don’t know for sure.
KVO is an OS X thing, introduced in 10.3. Why it uses this approach rather than taking a selector is a good question. I imagine it’s motivated by the desire to allow subclasses to override superclasses’ observation behaviour, and perhaps there might also be a performance argument (it *might* make it more likely that the -observeValueForKeyPath: method hits the method cache, and/or provide additional opportunities to use IMPs). Kind regards, Alastair. -- http://alastairs-place.net _______________________________________________ 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