Could not load NIB in bundle Xcode8

Viewed 463

I've followed a tutorial but when I try to run my code it crashed because it couldn't load NIB in bundle.

Here's my code:

class BuyPremiumView: UIView {

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

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

// MARK: - Private Helper Methods

// Performs the initial setup.
fileprivate func setupView() {
    let view = viewFromNibForClass()
    view.frame = bounds
    view.autoresizingMask = [
        UIViewAutoresizing.flexibleWidth,
        UIViewAutoresizing.flexibleHeight
    ]
    addSubview(view)
}

// Loads a XIB file into a view and returns this view.
fileprivate func viewFromNibForClass() -> UIView {
    let bundle = Bundle(for: type(of: self))
    let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
    let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
    return view
}

}

Does anybody know how to fix this?

1 Answers
Related