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 16:07:53 -0700
- Feedback-id: 167118m:167118agrif8a:167118sS5zSm_QeE:SMTPCORP
On Sep 22, 2016, at 15:45 , Gabriel Zachmann <email@hidden> 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 (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