John Stoneham <mailto:captnjamesk...@gmail.com> wrote (Monday, May 3, 2010 6:59 AM -0500):

Here's the scenario. In my (OS X) app's preferences, I'd like the user to be
able select between sets of preference settings, and I'd like to be able to
use NSUserDefaults for this without having to deal with extra plists.

Here's an example to illustrate the idea. On the preferences page there is a
combo box, where the user can pick a "theme" or enter the name of a new
theme. The settings for the theme are some check buttons which have
different states for the different themes. Obviously, the current state is
easy with NSUserDefaults. But I can't figure out how to have each "theme"
state stored in NSUserDefaults.

I think what you're trying to do is create a set of nested pref values that can get swapped out, while accessing the current set using bindings.

The approach I'd take is to organize all of the theme-related settings into a single dictionary. You can then store one dictionary in NSUserDefaults as the current or active theme set (i.e. "ActiveTheme"). Now set all of your bindings to reference the values in that dictionary (i.e. button.value = ActiveTheme.someSetting).

Now, create an array or another dictionary where you can store all of the themes that aren't active (i.e. "InactiveThemes"). When the user choose a theme, insert the active theme into the inactive collection and replace the active theme dictionary with the chosen one. Writing both back to the NSUserDefaults should notify any observers that the values along those key-value-paths have changed.

--
James Bucanek

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to