iosswiftswift2uitextinput

UITextInputMode.activeInputModes() crashes in Swift 2


I want to get UITextInputMode in Swift 2 but UITextInputMode.activeInputModes() crashes.

    let x = UITextInputMode.activeInputModes() // crash here

    for t in x {
        print(t)
    }

Solution

  • It is a bug in Xcode 7 as mentioned HERE. Which says:

    Summary:

    Prior to the Xcode 7 GM, UITextInputMode.activeInputModes() returned an array of UITextInputMode instances. However, in the Xcode 7 GM, the method signature in the header file and documentation states that it returns an array of Strings, which is incorrect. As a result, code that uses activeInputModes correctly no longer compiles, and attempting to use activeInputModes in a Playground throws an exception.