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.

It’s not that there *can’t* be a better mechanism, just that there isn’t***.


** In the “didEnd” selector mechanism, the context parameter is likely used for 
actual context information, rather than for identifying the source of the 
invocation. It can be used that way with KVO notifications, too, but the fact 
that they’re funneled through a single method in the observer object means that 
the context is implicitly known anyway, and the context parameter has been 
appropriated as a marker for the source of the observation.

*** Yet. KVO is one of the things that Swift hasn’t touched, even though it 
doesn’t translate very naturally. I believe (suspect) that’s because there’s an 
intention to replace it with a completely re-designed property notification 
system at some indefinite future time, but I’ve seen no discussion of what a 
new observer architecture might look like.

_______________________________________________

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

Reply via email to