Problem with bindings to user defaults
Problem with bindings to user defaults
- Subject: Problem with bindings to user defaults
- From: Bob Smith <email@hidden>
- Date: Sat, 26 Apr 2008 19:32:26 -0700
I have an array of simple values, i.e. NSStrings or NSDates, and I
want to store that array in user defaults. I also want the array to
be editable in the preferences UI. I set up a single-column table
and bind the table column to an NSArrayController instance that is
bound to the desired key in the Shared Defaults controller. The
model property key in the table column binding is blank because the
values are the actual objects in the array, not properties of those
objects. So far so good.
If the array already exists in user defaults and contains values,
those initially appear in the table. Using -add: and -remove: in the
array controller will add and remove array values. But the values
can't be edited! Any attempt to edit throws an exception about
NSString, or NSDate, or whatever, not being key-value coding
compliant for "" (an empty key). The table, or maybe the array
controller, doesn't seem able to simply replace the value object in
the array, it just tries to set a new value for a key in that object,
even though no key was given. Yet the table/controller had no
trouble loading pre-existing values correctly for initial display,
despite not having a property key.
Am I doing something wrong when setting up the bindings? Is there
some other way to edit a list of values without using a table? Is
this just a limitation in bindings to a table? I've been through the
docs and examples but never found any clues. I've run into this a
couple of times now, and always just ended up building a temporary
model of "wrapper" objects for the table binding, with controller
code to move values in and out of user defaults. Not really a lot of
code to write, but it seems like this should be a no-code-required
task. I suspect I am missing something really obvious, but I'm quite
happy to feel dumb if someone can point out my error.
Thanks!
Bob
_______________________________________________
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