NSUserDefaultsController and multiple sets of preferences?
NSUserDefaultsController and multiple sets of preferences?
- Subject: NSUserDefaultsController and multiple sets of preferences?
- From: Uli Zappe <email@hidden>
- Date: Tue, 19 Oct 2004 22:57:28 +0200
Hi all,
although a lot has already been discussed with regards to
NSUserDefaultsController and bindings, it seems I've run into still
another problem. ;-)
I'm writing a small Cocoa application that is a re-implementation of an
existing Carbon app, and is supposed to be a showcase for Cocoa.
Therefore, I want it not only to work but to be as elegant as possible.
Basically, the app allows users to store several settings that control
a hardware device that's connected to the computer. This is very simple
and seems to be a clear task for NSUserDefaultsController.
However, there's one specific thing about this app: there may be
*several* of these hardware devices connected to the computer; how many
of them, is, of course, unknown at compile time.
Some settings are global to all connected hardware devices. It's very
easy to store these settings with NSUserDefaultsController. (Like some
other people from this list I ran into the limitation that you can't
additionally bind a model object to NSUserDefaultsController, but in
the case of my app it's totally sufficient to use NSUserDefaults as the
storage location for the data and query it if necessary.)
However, other settings are on a per-hardware-device basis. The GUI
just adds Tabs to a Tab view for each additional hardware device, but
the controls inside the Tab view remain the same, and therefore their
Model Key Paths remain the same, too.
Ideally, the preferences would be structured hierarchically:
Device1 = {firstKey = value; secondKey = value;};
Device2 = {firstKey = value; secondKey = value;};
but an indexed version would also be OK (this is how it's done in the
Carbon version of the app):
firstKey1 = value;
secondKey1 = value;
firstKey2 = value;
secondKey2 = value;
I've thought a lot about this, but can't come up with an elegant
solution with as little glue code as possible. Obviously, I've thought
of binding the respective views to an NSArrayController with model
objects which in turn bind to NSUserDefaultsController, but that
doesn't seem to work in both directions. Another possibility would be
to update the Model Key Paths of the GUI views in accordance to the
selected Tab, but I can't think of a way to do this without introducing
as many lines of code as the classic glue code would have. Ideally,
there would be a way to let the Model Key Path reflect a view hierarchy
(values.key1.tab1 [Shared User Defaults]), but I don't see how this
could be achieved with Interface Builder.
Does anyone have an idea how to approach this elegantly?
Thanks a lot for your insight!
Bye
Uli
________________________________________________________
Uli Zappe, Solmsstraße 5, D-65189 Wiesbaden, Germany
http://www.ritual.org
Fon: +49-700-ULIZAPPE
Fax: +49-700-ZAPPEFAX
________________________________________________________
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden