views:

393

answers:

1

OK, I'm feeling really REALLY stupid for asking this question, but I've managed to stump myself so hard that I doubt I have the proper detachment to figure out the answer for myself any more. My apologies in advance...

I have been playing around with bindings for a while now and LOVE them. That and the KVO/KVC conventions built into Objective-C 2.0 have allowed me to dramatically slim down my applications while increasing their reliability, flexibility, etc. I say this for no other reason than to illustrate that I am at least moderately comfortable with bindings in general. That being said, my problem is this:

I have an application where I'd like to store an editable set of keywords by way of the preferences controller. Easy, right? Unfortunately, for the life of me I can't figure out how to do it. I set up an array controller and point it to the shared preferences object and give it a keypath for the array. The problem is that the objects being stored in the array are NSStrings and I don't see how NSStrings can be KVC-compliant for this kind of operation due to the lack of any "stringValue/setStringValue" methods. Without those, what keypath do I use in the NSTableView I have set up to facilitate manipulation of that list?

Also, since the shared preferences object is not one that I own, I'm not sure how to go about setting up a new array to represent an unedited/newly installed state. (Registering them as defaults doesn't seem to be working for me.)

So to reiterate my questions more succinctly: How can you bind a table view to an array of NSStrings and how can you store said array in an application's preferences?

Any pointers or advice that you can offer would be VERY much appreciated. The headaches I'm getting from this are starting to get the better of me. :)

+1  A: 

You don't. You hold an array of model objects, each with at least one property (that of the string), and you bind the table column through an array controller to this array, with the model key path set to that of the string property.

Assuming your app is not simply a list-of-strings editor, you probably have other things that you can move into this model class. You should do so.

Peter Hosey
That's the conclusion I kept being drawn to, but for some reason couldn't bring myself to actually believe it. Thank you for the clarification. As far as putting it into the apps preferences goes, I presume that should be done via a value transformer which would convert it to/from NSData? Also, what would be the best way to seed initial values for that array?Again, thank yo for the info...
Chronor
Normally, you bind views or other controllers to user defaults using NSUserDefaultsController. That class also has methods for working with the initial values.
Peter Hosey
Thanks Peter. This was very helpful. I was doing just the same - binding a NSArray of NSSTrings to a ComboBox and I was wondering what the key path may be. Now I put all my strings into a new class and it works perfectly.
Holli