• 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: how do I put ints in for NSUserDefaults for keys?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how do I put ints in for NSUserDefaults for keys?


  • Subject: Re: how do I put ints in for NSUserDefaults for keys?
  • From: Matt Neuburg <email@hidden>
  • Date: Thu, 27 Apr 2006 12:19:15 -0700
  • Thread-topic: how do I put ints in for NSUserDefaults for keys?

On Wed, 26 Apr 2006 11:54:36 -0700, Matt Neuburg <email@hidden> said:
>On Wed, 26 Apr 2006 13:54:38 -0400, "Alan Smith" <email@hidden>
>said:
>>I need to, well, want to, put numbers in for the keys of my NSDictionary
>>that will go into the NSUserDefaults. It works to put them in as a string,
>>like this, @"3" but then I want to get them back as a number, not a string.
>>I tried type-casting: (int)[dict valueForKey:key] but it comes out as way to
>>many numbers that seem to have no resemblance to the number I originally put
>>in. The question is: How do I put in numbers as keys and then be able to get
>>them out as numbers?
>>
>>I want to do it with numbers because I'll be taking the string values of
>>each key, the string will then be put in textFields. Each field has it's own
>>tag and the keys number represents the field the value is supposed to go
>>into.
>
>(1) To turn a string representing an integer to an actual integer, take its
>intValue.
>
>(2) To use a number directly as a key, I suppose you could use an NSNumber,
>though to be quite honest I've never tried it.
>
>(3) If you really want to guarantee that everything comes out the way you
>want, why not put more info in the dictionary? It seems to me you're relying
>on conversions when in fact you could just be storing and retrieving the
>info you want, directly.

And I should have added, (4) the way to store things by number (when the
number is an integer) might be to use an array instead of a dictionary. m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>



 _______________________________________________
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

  • Prev by Date: Re: Getting a table to resize columns. I'm doing everything right but it's not working?
  • Next by Date: Re: Encoding/Decoding Multiple Objects in MyDocument
  • Previous by thread: Re: how do I put ints in for NSUserDefaults for keys?
  • Next by thread: NSString init
  • Index(es):
    • Date
    • Thread