RockGuitarist1 RockGuitarist1 - 3 months ago 43
iOS Question

iOS App/Keyboard Plugin Invalidated

So I have been taking on the task to learn Swift and the XCode interface to get into iOS development. To do this, I have been practicing with a few projects that will help get me some exposure on all of this, so I took up one project that makes a custom keyboard. However, since I am guessing the tutorials are written in older versions of Swift/XCode, that I keep getting errors, one in particular.

Anytime I go into Settings and add my custom keyboard, I go to use it, and whenever I toggle it in the Keyboard Switcher, the keyboard crashes and defaults back to original iOS keyboard (This happens on both the Simulator and my phone. Also, the target iOS is correct). Upon that crash, I get this error:

plugin CalculatorKeyboard plugin myName.CalculatorKeyboard.Calculator interrupted
plugin CalculatorKeyboard plugin myName.CalculatorKeyboard.Calculator invalidated


Current code that I am using:

class KeyboardViewController: UIInputViewController {

var customInterface: UIView!

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

let nib = UINib(nibName: "Calculator", bundle: nil)
let objects = nib.instantiateWithOwner(self, options: nil)
customInterface = objects[0] as! UIView
}

override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(customInterface)
}
}


Old code:

// var customInterface: UIView!

override func viewDidLoad() {
super.viewDidLoad()
loadInterface()
}

func loadInterface() {
let calculatorNib = UINib(nibName: "Calculator", bundle: nil)
let objects = calculatorNib.instantiateWithOwner(self, options: nil)
view = objects[0] as! UIView
}


I was hoping I could get some help on this, since I haven't been able to find any answers on Google. Thank you! :)

NOTE: I would prefer if I could use the Old Code, since it is a lot cleaner being in its own function.

Answer

This will work

override func viewDidLoad() {
        super.viewDidLoad()
        let nib = UINib(nibName: "KeyboardView", bundle: nil)
        let objects = nib.instantiateWithOwner(self, options: nil)
        view = objects[0] as! UIView;

    }

There is also a nice demo app on this which is written in both swift and objective-C https://github.com/iManiaq/ios-color-keyboard

Edit go to setting->general->keyboards there you add your keyboard

enter image description here

enter image description here

enter image description here

Comments