我正在尝试以下代码进行键盘本地化,该代码可在Swift3中使用。 我从下面的链接中获取了此代码:- iPhone: Change Keyboard language programmatically
但是它在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 ""
}
}
答案 0 :(得分:0)
您只需要定义函数将要返回的类型。
let language: SomeTypeHere = type.getKeyboardLanguage()
干杯!