• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Stupid objective-c question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid objective-c question


  • Subject: Re: Stupid objective-c question
  • From: Alastair Houghton <email@hidden>
  • Date: Fri, 23 Sep 2016 09:50:07 +0100

On 23 Sep 2016, at 00:07, Quincey Morris <email@hidden> wrote:
>
> 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.

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 (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


References: 
 >Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Doug Hill <email@hidden>)
 >Re: Stupid objective-c question (From: Jens Alfke <email@hidden>)
 >Re: Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Stupid objective-c question
  • Next by Date: Re: Stupid objective-c question
  • Previous by thread: Re: Stupid objective-c question
  • Next by thread: Re: Stupid objective-c question
  • Index(es):
    • Date
    • Thread