Created
April 20, 2010 12:04
-
-
Save stuffmc/372349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First get the list of ISO Codes | |
NSArray *countries = [NSLocale ISOCountryCodes]; | |
// Then create an empty array for the list of country with both code and name | |
NSMutableArray *namedCountries = [NSMutableArray arrayWithCapacity:[countries count]]; | |
NSUInteger countryIndex = 0; | |
// Loop over the codes and have their localized names | |
for (NSString *code in countries) { | |
NSString *name = [[NSLocale currentLocale] displayNameForKey:NSLocaleCountryCode value:code]; | |
NSDictionary *countryDictionary = [NSDictionary dictionaryWithObjectsAndKeys:code, @"code", name, @"name", nil]; | |
[namedCountries insertObject:countryDictionary atIndex:countryIndex++]; | |
} | |
// Now sort on the names | |
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES] autorelease]; | |
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; | |
NSArray *sortedCountries = [namedCountries sortedArrayUsingDescriptors:sortDescriptors]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment