Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the code for the local currency from an NSLocale?

Can I get the code for the local currency from an NSLocale? I tried this:

NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"] autorelease];
NSString *currencyCode = [locale objectForKey:NSLocaleCurrencyCode];

but currencyCode comes back as nil (I wanted "EUR", or similar).

like image 584
Simon Avatar asked Nov 14 '11 18:11

Simon


1 Answers

Your code works perfectly fine for me in a regular Macintosh app.

NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"] autorelease];
NSString *currencyCode = [locale objectForKey:NSLocaleCurrencyCode];
NSLog( @"currencyCode is %@", currencyCode );

displays this in the console:

2011-11-14 14:53:33.784 Testing[26388:707] currencyCode is EUR

Are you trying to build this as a command line (Foundation) app or something non-traditional-Mac-like?

like image 137
Michael Dautermann Avatar answered Oct 05 '22 00:10

Michael Dautermann