I am trying below code for keyboard localization which work in Swift3. I have taken this code from below link:- iPhone: Change Keyboard language programmatically
But it gives below error in Swift 4.
a) let language = type.getKeyboardLanguage()
for this line it gives error as:- Expression type '(_) -> _' is ambiguous without more context
b)In switch case for below code
switch self {
case .one:
return "en"
case .two:
return "ru"
case .three:
return ""
case .four:
return ""
}
It gives error as 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 ""
}
}