简体   繁体   中英

Keyboard Localization of type Decimal Pad

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

    }

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

let language: SomeTypeHere = type.getKeyboardLanguage() 

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM