如何在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