2

I have the following class representing a button in my iOS 8 custom keyboard:

internal class KeyButton: UIButton {

    required init(char: Character) {
        super.init()
    }


    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

Since KeyButton is not initialised via storyboard the constructor (coder: NSCoder) would never be called.

The problem is that I am required to implement (coder: NSCoder) constructor, when I run the app I receive the exception plugin interrupted when instantiating KeyButton.

Why am I required to implement (coder: NSCoder) constructor although I instantiate everything programatically

1 Answer 1

1

It has nothing to do with the coder. UIButton's init() calls init(frame: CGRect), which you haven't implemented. Add the following, and you should be good to go...

override init(frame: CGRect ) {
    super.init(frame: frame)
    println("Button frame allocated")
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.