• 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: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!


  • Subject: Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • From: Keary Suska <email@hidden>
  • Date: Tue, 10 Mar 2015 12:19:08 -0600

On Mar 10, 2015, at 11:50 AM, Sean McBride <email@hidden> wrote:

> Hi all,
>
> Can anyone think of a sitation where using removeObserver:forKeyPath: works correctly, then modernizing the code to use removeObserver:forKeyPath:context: breaks things?
>
> Long story: I have a custom NSView subclass that exposes a custom binding.  In bind: it does addObserver:forKeyPath:options:context:.  In unbind: it does removeObserver:forKeyPath:.  If I update unbind: to use the 'context' version it breaks.
>
> Specifically, if I have several of these views onscreen (all bound to the same NSObjectController) then remove all but one of the views from the view hierarchy, the remaining one no longer receives any KVO notifications.  I've put logs everywhere, and subclassed NSObjectController and implemented add&removeObserver methods to log and call super.  All the log output is the same in the working & broken cases except the deliberate difference between using removeObserver: with or without the context.  I am surprised to see this backtrace however:
>
> -[MyObjectController removeObserver:forKeyPath:]
> -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] ()
> -[NSController removeObserver:forKeyPath:context:] ()
> -[MyObjectController removeObserver:forKeyPath:context:]
> -[MyView unbind:]
> ...
>
> Odd that NSObjectController removeObserver:forKeyPath:context: calls removeObserver:forKeyPath:, no?
>
> Any clues would help... :)

Have you checked observationInfo at each point to ensure that observation is being added/removed exactly as you expect?

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

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: 
 >removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?! (From: Sean McBride <email@hidden>)

  • Prev by Date: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • Next by Date: Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • Previous by thread: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • Next by thread: Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • Index(es):
    • Date
    • Thread