我正在尝试以下代码用于在 Swift3 中工作的键盘本地化。我从以下链接中获取了此代码:- iPhone:以编程方式更改键盘语言
但它在 Swift 4 中给出了以下错误。
a)let language = type.getKeyboardLanguage()
对于这一行,它给出的错误如下:-Expression type '(_) -> _' is ambiguous without more context
b)在以下代码的开关情况下
switch self {
case .one:
return "en"
case .two:
return "ru"
case .three:
return ""
case .four:
return ""
}
它给出了错误Pattern cannot match values of type 'ViewController' for cases in Switch
。
override var textInputMode: UITextInputMode? {
let language = type.getKeyboardLanguage()
if language.isEmpty {
return super.textInputMode
} else {
for tim in UITextInputMode.activeInputModes {
if tim.primaryLanguage!.contains(language) {
return tim
}
}
return super.textInputMode
}
}
func getKeyboardLanguage() -> String {
switch self {
case .one:
return "en"
case .two:
return "ru"
case .three:
return ""
case .four:
return ""
}
}