Last active
August 29, 2015 14:00
-
-
Save nonstriater/fa4dcb03b5b8087c53e9 to your computer and use it in GitHub Desktop.
NSLocale中取出国家country信息并按照国家名字排序
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
//NSLocale中取出国家country信息并按照国家名字排序 | |
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"]; | |
NSArray *countryCodes = [NSLocale ISOCountryCodes];// 所有国家编码 | |
NSMutableArray *countriesUnsorted = [[NSMutableArray alloc] initWithCapacity:countryCodes.count]; | |
for (NSString *countryCode in countryCodes) { | |
NSString *displayNameString = [locale displayNameForKey:NSLocaleCountryCode value:countryCode];// 获得编码对应的国家名字 | |
NSDictionary *cd = @{@"name": displayNameString, @"code":countryCode}; | |
[countriesUnsorted addObject:cd]; | |
} | |
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];//排序方式 | |
NSArray *sortDescriptors = @[sortDescriptor]; | |
_regionArray = [countriesUnsorted sortedArrayUsingDescriptors:sortDescriptors]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment