Re: Using NSUserDefaultsController with radio buttons
Re: Using NSUserDefaultsController with radio buttons
- Subject: Re: Using NSUserDefaultsController with radio buttons
- From: Derrick Bass <email@hidden>
- Date: Mon, 24 Apr 2006 13:21:08 -0700
On Apr 24, 2006, at 9:13 AM, Matteo Manferdini wrote:
What I want to do is set a string for the key. The key is specified
in the controller's attributes, but I don't want to store numeric
values for that key. I mean, if the key is "userContinent", I wold
like to set the value to "America" or "Europe", not just 1 or 2.
That's the part I'm missing.
I usually use a value transformer (a subclass of NSValueTransformer)
to do this sort of thing. It's kind of a pain, because it seems like
it should be doable all from IB, and this requires code.
If you make a small up-front commitment, you can easily write a
single NSValueTransformer subclass that takes an NSDictionary and
converts back and forth between integers and strings. For the reverse
transformation I just iterate through the dictionary, since it is
unlikely to be very large.
You can then reuse the class with different dictionaries for all the
places where you need to do this conversion.
I generally give each radio button a unique tag and bind to the
selectedTag binding of NSMatrix; my value transformer throws when it
gets an unexpected value (and I always choose 0 to be unexpected)
which should help me in case I change the radio button in IB and
forget to make a corresponding change to the transformer.
Derrick
_______________________________________________
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