Code:
class HeaderView: UIView {
@IBOutlet weak var titleLabel: UILabel!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
finishInit()
}
func finishInit() {
titleLabel.backgroundColor = UIColor.white
}
func setView(withTitle title: String?) {
titleLabel.backgroundColor = UIColor.white
titleLabel.text = title
}
Crash:
On finishInit() method, while setting label background color
fatal error: unexpectedly found nil while unwrapping an Optional value
But same, on setView() method, is not crashing.