• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using NSUserDefaultsController with radio buttons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Using NSUserDefaultsController with radio buttons (From: Matt Neuburg <email@hidden>)
 >Re: Using NSUserDefaultsController with radio buttons (From: Matteo Manferdini <email@hidden>)

  • Prev by Date: Re: Getting a machine's MAC address
  • Next by Date: Re: First launch window
  • Previous by thread: Re: Using NSUserDefaultsController with radio buttons
  • Next by thread: Should Cocoa Apps have splash screens at all ?
  • Index(es):
    • Date
    • Thread