• 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: NSUserDefaultsController not updating defaults via binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUserDefaultsController not updating defaults via binding


  • Subject: Re: NSUserDefaultsController not updating defaults via binding
  • From: Matt Neuburg <email@hidden>
  • Date: Thu, 22 Jan 2009 10:48:03 -0800
  • Thread-topic: NSUserDefaultsController not updating defaults via binding

On Fri, 16 Jan 2009 15:24:45 -0800, Luke Evans <email@hidden> said:
>I tried a set up where some UI (slider) bound to a property on a
>class, and separately this class' init programmatically set up a
>binding to NSUserDefaultsController sharedUserDefaultsController to
>initialise both the property and indirectly the slider control to
>which it was also bound.
>
>This worked great for initialisation.  The property and slider were
>indeed initialised to the value in the user defaults, and I could
>change this externally and see the initial properly/slider value
>change.  However, I was expecting that this code (being a binding)
>would also result in the user defaults being updated as the property
>value changed (as a result of moving the slider or writing to the
>property in another way).  Unfortunately, this doesn't happen.
>
>I've used NSUserDefaultsController many times in direct binding with
>UI controls (like everyone else), and it works perfectly
>bidirectionally with the simple binding.   I have also used
>programmatic binding to and observing of NSUserDefaultsController
>sharedUserDefaultsController many times to listen to properties
>changing in a one-way sense.  This is the first time I have tried this
>kind of configuration.
>
>There's an easy work around - just use NSUserDefaults to read the
>initial value, and to manually update the default when the property
>changes - but the attraction of a binding was hard to resist.  The
>docs also seem to keep hinting "use NSUserDefaults as the primary
>access - don't use NSUserDefaultsController for everything" (my
>paraphrase), but the reasons behind this recommendation aren't spelled
>out.
>
>Has anyone had similar experiences?  Is it unreasonable to expect this
>kind of binding configuration to work?

This is a very old source of confusion, so next time before posting a
question like this, check the archives, where the matter has been beaten to
death. Basically the short answer to your question is that there is no such
thing as a bidirectional binding; but some classes (i.e. NSControls) know
how to set up a binding in conjunction with KVO in such a way that changes
at either end are reflected back to the other end. Your programmatic binding
is between a class property and the user defaults, neither of which knows
how to do that, so you didn't get bidirectionality. A simple solution is to
add a second binding between the class property and the user defaults
running the other way. m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
One of the 2007 MacTech Top 25: <http://tinyurl.com/2rh4pf>
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>



_______________________________________________

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

  • Prev by Date: Re: NSTextView and front/middle/back ellipses
  • Next by Date: Re: Log4Cocoa
  • Previous by thread: NSUserDefaultsController not updating defaults via binding
  • Next by thread: string bounding rect methods
  • Index(es):
    • Date
    • Thread