Check out the following code.
class MyViewCell: UICollectionViewCell {
@IBOutlet weak var title: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
didLoad()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
didLoad()
}
/// Common init code.
func didLoad() {
self.title = UILabel()
self.title.textColor = .white
...
}
}
My app crashes at self.title.textColor = .white
with the following error:
fatal error: unexpectedly found nil while unwrapping an Optional value
Any idea why UILabel() returns nil
?