• 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: Quincey Morris <email@hidden>
  • Date: Thu, 22 Sep 2016 10:53:11 -0700
  • Feedback-id: 167118m:167118agrif8a:167118sS5zSm_QeE:SMTPCORP

On Sep 22, 2016, at 03:16 , Gabriel Zachmann <email@hidden> 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.


** That is, a superclass ‘addObserver’ may be in common code that’s used by all the subclasses, or it may be a private observation that’s separate from what subclasses use. Where the observation is created is insufficient to determine whether it’s an observation “you” created, or you “care about”.
_______________________________________________

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


  • Follow-Ups:
    • Re: Stupid objective-c question
      • From: Uli Kusterer <email@hidden>
    • Re: Stupid objective-c question
      • From: Sandor Szatmari <email@hidden>
    • Re: Stupid objective-c question
      • From: Gabriel Zachmann <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>)

  • Prev by Date: Re: Entitlements for non-appstore developer-id signed apps
  • Next by Date: Re: Maximum image size ?
  • Previous by thread: Re: Stupid objective-c question
  • Next by thread: Re: Stupid objective-c question
  • Index(es):
    • Date
    • Thread