Thank you, patron.
If someone is interested or wants to find the same solution, this 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()
Dan Morgan Feb 02 '09 at 11:09 2009-02-02 11:09
source share