0

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 ""
        }

    }
Sharad Chauhan
  • 4,821
  • 2
  • 25
  • 50
poojathorat
  • 1,200
  • 2
  • 9
  • 19

1 Answers1

0

You just need to define a type that your function is expected to return.

let language: SomeTypeHere = type.getKeyboardLanguage() 

Cheers!

ekscrypto
  • 3,718
  • 1
  • 24
  • 38
  • it is giving error to type. I have tried with below line:- let language : String = type.getKeyboardLanguage() Still it is giving error as Expression type '(_) -> _' is ambiguous without more context. – poojathorat Jul 19 '18 at 06:51
  • Then you need to check where you define the type.getKeyboardLanguage() function. You might have some generics in there that cause this to not work in Swift4 – ekscrypto Jul 19 '18 at 07:17