On Fri, 16 Jan 2009 15:24:45 -0800, Luke Evans <[email protected]> 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 protected], <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 protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
