-5

This is my class of a UIView:

class overlap: UIView{
    init() {
        super.init(frame: UIScreen.main.bounds)
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        fatalError("init(coder:) has not been implemented")
    }
}

It should just fill up the screen. When I add the view in Storyboard with constraints pinned to the edges of the screen, it crashes when I launch the app. The error comes up as stated in the code above.

Creating and adding the subclass programmatically works with this init function:

override init(frame: CGRect) {
    super.init(frame: frame)
}

But I want it reusable through Storyboard, without adding code. What is wrong with my code, and is it even possible what I want?

Thanks!

1
  • 5
    fatalError("init(coder:) has not been implemented") – guess what gets called when instantiating a storyboard. Commented Sep 14, 2017 at 23:11

1 Answer 1

4

it crashes when I launch the app

Because that is what your code told it to do.

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

fatalError means "crash me".

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.