Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get NSLocale from currency code?

I am trying this:

NSDictionary *components = [NSDictionary dictionaryWithObject:@"USD" forKey:NSLocaleCurrencyCode];
NSString *localeIdentifier = [NSLocale localeIdentifierFromComponents:components];
NSLocale *localeForDefaultCurrency = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier];

It creates NSLocale object but it does`t contain any regional information. For example,

[localeForDefaultCurrency objectForKey:NSLocaleCountryCode];

returns nil;

Any idea how to get NSLocale from currency code?

like image 222
kastet Avatar asked Aug 02 '11 07:08

kastet


1 Answers

As posted by some Guest in pastebin:

NSDictionary *components = [NSDictionary dictionaryWithObject:@"USD" forKey:NSLocaleCurrencyCode];
NSString *localeIdentifier = [NSLocale localeIdentifierFromComponents:components];
NSLocale *localeForDefaultCurrency = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier];

[localeForDefaultCurrency objectForKey:NSLocaleCountryCode];
like image 71
Filipe Teixeira Avatar answered Oct 19 '22 16:10

Filipe Teixeira