如何在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];
}
而且在斯威夫特我不能从这里经过:
if (!countriesPickerShown) {
var countries: NSMutableArray = NSMutableArray()
countries = NSMutableArray.arrayWithCapacity((NSLocale.ISOCountryCodes).count) // Here gives the Error. It marks NSLocale.ISOCountryCodes and .count
难道你们有谁知道对这个?
感谢
我得到的数组零个元素! – Kirti