• 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: Quincey Morris <email@hidden>
  • Date: Wed, 11 Mar 2015 23:28:06 +0000

On Mar 11, 2015, at 15:03 , Sean McBride <email@hidden> wrote:

> It's here:

I just spent a few minutes with it. A couple of things:

— I don’t think it’s a very good idea to do this (slightly abbreviated from your source):

> - (void)bind:(NSString*)inBindingName toObject:(id)inObservableObject withKeyPath:(NSString*)inKeyPath  options:(NSDictionary*)inOptions {
> 	[inObservableObject addObserver:self  forKeyPath:inKeyPath options:0 context:context];
> 	[super bind:inBindingName toObject:inObservableObject withKeyPath:inKeyPath options:inOptions];
> }

The standard implementation of bindings, which you’re using when you invoke super, *also* adds the exact same observation as you just did (though with a different or nil context, presumably).

When you invoke super in ‘unbind', I guess it’s using the context-less form of removeObserver.

I don’t have an explanation of exactly why that might fail, but it certainly seems a lot like the conditions for bug I talked about earlier. You have the same object observing the same property of the same target twice.

I would suggest you simply don’t do this to the binding, or better still don’t use a binding here at all. But of course my opinion here is basically valueless, since I don’t know the design of your app.

— I commented out the super ‘bind’ in the above method to see what would happen. After also commenting out the various asserts, I ended up with this log output:

> •BIND: ptr: 0x610000140bb0, tag: 1, name: "crosshairsTransform", context: 123456
> •BIND: ptr: 0x610000140c60, tag: 2, name: "crosshairsTransform", context: 123456
> •BIND: ptr: 0x610000140b00, tag: 3, name: "crosshairsTransform", context: 123456
> •OBSERVE: ptr: 0x610000140bb0, tag: 1: keyPath: "selection.crosshairs", context: 123456
> •OBSERVE: ptr: 0x610000140c60, tag: 2: keyPath: "selection.crosshairs", context: 123456
> •OBSERVE: ptr: 0x610000140b00, tag: 3: keyPath: "selection.crosshairs", context: 123456
> •UNBIND: ptr: 0x610000140c60, tag: 2, name: "crosshairsTransform", context: 123456, hasInfo: 0
> •UNBIND: ptr: 0x610000140b00, tag: 3, name: "crosshairsTransform", context: 123456, hasInfo: 0
> •DEALLOC: ptr: 0x610000140b00, tag: 3
> •DEALLOC: ptr: 0x610000140c60, tag: 2
> •OBSERVE: ptr: 0x610000140bb0, tag: 1: keyPath: "selection.crosshairs", context: 123456

which I think is the behavior you’re looking for. (Of course, the app crashed shortly after that, because the object controller didn’t have any content, or some such consequence of the missing binding.)

To my mind, that confirms that the multiple-identical-observation scenario is the problem.


_______________________________________________

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: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
      • From: Jonathan Mitchell <email@hidden>
    • Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
      • From: Sean McBride <email@hidden>
References: 
 >removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?! (From: Sean McBride <email@hidden>)
 >Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?! (From: Quincey Morris <email@hidden>)
 >Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?! (From: Sean McBride <email@hidden>)
 >Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?! (From: Quincey Morris <email@hidden>)
 >Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?! (From: Sean McBride <email@hidden>)

  • Prev by Date: Re: Cocoa GUI app getting slower on MacPro or MacMini when disconnecting all screens
  • Next by Date: Swift Keypress KeyDown NSResponder input function needed.
  • Previous by thread: Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • Next by thread: Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • Index(es):
    • Date
    • Thread