When the value is passed for UILabel the error appears :
Can't unwrap Optional.None
source code:
@IBOutlet var rowLabel : UILabelAlso error appears in label in the template for UITable when I appropriate new meaning:
var row: String? { didSet { // Update the view. println(row) rowLabel.text = row } }
let myCell : Cell = Cell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell") myCell.myLabel.text = "(indexPath.row)"
You must use newValue in willSet block, and oldValue in didSet block
example:
output:
row
is anOptional
and it can benil
, i.e.Optional.None
, so you need to unwrap it before assignment.If you don't, I guess the runtime will try to unwrap it anyway, but it will fail with that error whenever a
nil
value is encountered.Something like this should be safe
If
row
isnil
, it will never be assigned.