Bạn có thể nhận được một định danh cho một mã quốc gia với localeIdentifierFromComponents:
và sau đó nhận được displayName
của nó.
Vì vậy, để tạo ra một mảng với tên quốc gia mà bạn có thể làm:
NSMutableArray *countries = [NSMutableArray arrayWithCapacity: [[NSLocale ISOCountryCodes] count]];
for (NSString *countryCode in [NSLocale ISOCountryCodes])
{
NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]];
NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier];
[countries addObject: country];
}
Để sắp xếp nó theo thứ tự abc bạn có thể thêm
NSArray *sortedCountries = [countries sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
Lưu ý rằng các mảng được sắp xếp là không thay đổi.
Xin lỗi, nó là loại NSMutableArray; – user1036183
Chấp nhận một số câu trả lời (trên các câu hỏi trước của bạn) để bạn trao lại điều gì đó cho cộng đồng. – Jef