• 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: int to NSString?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: int to NSString?


  • Subject: Re: int to NSString?
  • From: Alastair Houghton <email@hidden>
  • Date: Mon, 25 Jun 2007 18:07:20 +0100

On 24 Jun 2007, at 06:49, Devraj Mukherjee wrote:

Hi everyone,

How do I convert an int to an NSString? Also is there an NSInt or a
NSInteger class?

See NSString's -stringWithFormat: method in the documentation for one method, and NSNumberFormatter for another. Which you use depends largely on the circumstances you're in; NSNumberFormatter is better if you're displaying a value to the user somehow, because it will choose a localised format that the user will understand (e.g. many Europeans expect the ',' to be a decimal separator and use either spaces or '.'s for thousands separators, which can cause significant confusion as that isn't the way English speaking countries typically punctuate numbers). Note, by the way, that because it's a subclass of NSFormatter, you can apply it to a control in Interface Builder and then communicate with your UI using numeric values directly, which saves you from doing any conversions yourself.


As for a class wrapper, try NSNumber (again, this has copious documentation). If you're coming from Java or Python or something, note that NSNumber is *just* a way to wrap a number; it doesn't provide any numeric operations.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

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


References: 
 >int to NSString? (From: "Devraj Mukherjee" <email@hidden>)

  • Prev by Date: Re: NSScrollView: General Question When does scrollRectToVisible does not scroll?
  • Next by Date: Re: int to NSString?
  • Previous by thread: Re: int to NSString?
  • Next by thread: Re: int to NSString?
  • Index(es):
    • Date
    • Thread