3

I'm using this code to get the list of countries:

for (NSString *code in [NSLocale ISOCountryCodes])
{
    NSString *identifier = [NSLocale localeIdentifierFromComponents:@{NSLocaleCountryCode: code}];
    NSString *countryName = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:identifier];
    NSLog(countryName);
}

This works fine in iOS 7.x but fails in iOS8 (beta 2) - with countryName always being nil.

Anyone found an alternative yet?

user623396
  • 1,537
  • 1
  • 17
  • 39

2 Answers2

5

I have also faced with such issue on iOS 8. Try to use systemLocale instead of currentLocale.

Pavel Malinnikov
  • 349
  • 5
  • 11
0
    let currentLocale : NSLocale = NSLocale.init(localeIdentifier :  NSLocale.current.identifier)
    let countryName : String? = currentLocale.displayName(forKey: NSLocale.Key.countryCode, value: countryCode)
    print(countryName ?? "Invalid country code")

Note: If you manually entered localIdentifier means IOS 8 not listed all country name (Eg: "en_US")