-2
let countryCodes = NSLocale.ISOCountryCodes()
for countryCode in countryCodes {
let dictionary = NSDictionary(object: countryCode, forKey: NSLocaleCountryCode)
if let aValue = dictionary[countryCode] {
print("country code of \(countryCode) is \(aValue)")
}
打印功能从未得到执行。但是,如果我删除了if let
,我可以得到countryCode
而不是aValue
,它总是会返回nil
。 我该如何解决这个问题?swift dictionary is returning nil
哇,谢谢。我不习惯initObjectForKey字典。我想我的教训。 – Suhaib