我将应用转换为swift 3
时出现此错误对成员'下标'的模糊引用
在本准则中:
internal func getSelectedLocale()->String{
let lang = Foundation.Locale.preferredLanguages
let languageComponents: [String : String] = Foundation.Locale.components(fromIdentifier: lang[0])
//Here is the error
if let languageCode: String = languageComponents[NSLocale.Key.languageCode]{
for locale in availableLocales {
if locale.languageCode == languageCode {
if locale.languageCode! == "en"{
return "en"}
else{
return locale.languageCode!+"-"+locale.countryCode!.uppercased()
}
}
}
}
return "en"
}
任何人都可以帮助我吗?
答案 0 :(得分:0)
由于components(fromIdentifier
返回[String:String]
,您必须通过rawValue
的{{1}}
Key
但实际上if let languageCode = languageComponents[NSLocale.Key.languageCode.rawValue] { ...
会返回一个国家/地区代码数组