אורי orihpt
אורי orihpt

Reputation: 2634

Crash when using loadNibNamed

This is my code:

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

required init?(coder: NSCoder) {
    super.init(coder: coder)
    commonInit()
}

func commonInit() {
    let mainBundle = Bundle.main
    mainBundle.loadNibNamed("iconView", owner: self, options: nil)
    addSubview(contentView)
    contentView.frame = self.bounds
    contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}

I copied it from step 8 in this tutorial that I've seen (I only changed the name in the code to my xib file: "iconView"). But for some reason it fails: fail I already tried all of the solutions in stackoverflow, but nothing helped me. Here is my xib file: xib file I really don't know what to do. I'm using Xcode 12 beta 6, iOS 14 beta 6 UPDATE Okay, a lot of people saied in the comments of the tutorial that

This causes an infinite-loop calling commonInit().

So now I know what the issue is, but I still don't know how to solve it. Any ideas?

Upvotes: 2

Views: 627

Answers (1)

gcharita
gcharita

Reputation: 8327

You probably have to remove Class from your View.

First select your View (in your case iconView):

enter image description here

and then clear whatever there is in the class field:

enter image description here

Upvotes: 3

Related Questions