• 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: Sean McBride <email@hidden>
  • Date: Thu, 12 Mar 2015 11:23:29 -0400
  • Organization: Rogue Research Inc.

On Wed, 11 Mar 2015 23:28:08 +0000, Quincey Morris said:

>— 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.

Thanks for your analysis; I concur with it.

Not using bindings isn't an option, at least not in the short/medium term.  The app was started back when we had ibplugins and uses bindings heavily.

Regarding your prescriptions, I was going to say 'but I'm doing it just as mmalc's old binding examples suggested' but then I went to look up the old BindingsJoystick sample code and see that it was updated in 2012, which I never noticed.  I swear they changed how they do things.  Now bind: and unbind: only call super if the binding name is not the class' own, and now they implement infoForbinding:.  My SCM history shows that unconditionally calling super was necessary for ibplugins to work properly, which is moot now.

So I guess my solution is to only call super in bind: and unbind: for binding names that aren't mine, and to also override infoForBinding: to return info for my own bindings, and again only call super for super's bindings.

Thanks!

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada

_______________________________________________

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

  • Prev by Date: Re: Cocoa GUI app getting slower on MacPro or MacMini when disconnecting all screens
  • Next by Date: Re: removeObserver:forKeyPath:context: fails; but removeObserver:forKeyPath: works?!
  • 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