我正在尝试:

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

它创建NSLocale对象,但不包含任何区域信息。例如,
[localeForDefaultCurrency objectForKey:NSLocaleCountryCode];

返回nil;

任何想法如何从货币代码获取NSLocale?

最佳答案

正如一些 guest 在pastebin中发布的那样:

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

[localeForDefaultCurrency objectForKey:NSLocaleCountryCode];

关于objective-c - 如何从货币代码获取NSLocale?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6908834/

10-10 08:58