我该如何在Swift中获得包含所有国家名称的数组?我尝试将我的Objective-C代码转换为Swift,原始代码如下:
if (!pickerCountriesIsShown) {
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];
}
在Swift中,我无法从这里传递:
if (!countriesPickerShown) {
var countries: NSMutableArray = NSMutableArray()
countries = NSMutableArray.arrayWithCapacity((NSLocale.ISOCountryCodes).count) // Here gives the Error. It marks NSLocale.ISOCountryCodes and .count
你们中有谁了解这个吗?
谢谢