Iphone, Obtaining a List of countries in an NSArray

Thanks chuck.

If anyone is interested or wanted to find the same solution here is my code for a sorted array of countries.

Objective-C:

NSLocale *locale = [NSLocale currentLocale];
NSArray *countryArray = [NSLocale ISOCountryCodes];

NSMutableArray *sortedCountryArray = [[NSMutableArray alloc] init];

for (NSString *countryCode in countryArray) {

    NSString *displayNameString = [locale displayNameForKey:NSLocaleCountryCode value:countryCode];
    [sortedCountryArray addObject:displayNameString];

}

[sortedCountryArray sortUsingSelector:@selector(localizedCompare:)];

Swift:

let locale = NSLocale.currentLocale()
let countryArray = NSLocale.ISOCountryCodes()
var unsortedCountryArray:[String] = []
for countryCode in countryArray {
    let displayNameString = locale.displayNameForKey(NSLocaleCountryCode, value: countryCode)
    if displayNameString != nil {
        unsortedCountryArray.append(displayNameString!)
    }
}
let sortedCountryArray = sorted(unsortedCountryArray, <)

Swift 3

    let locale = NSLocale.current
    let unsortedCountries = NSLocale.isoCountryCodes.map { locale.localizedString(forRegionCode: $0)! }
    let sortedCountries = unsortedCountries.sorted()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)