Why is the UMLableViewCell textLabel property optional?

A UITableViewCell detailTextLabel must be optional , which is documented , but why is the property textLabeloptional?

+4
source share
2 answers

Short answer: resource conservation. The textLabel property is optional to allow UILabel to initialize lazily. In other words, a property remains zero unless you are actually trying to access it.

You can verify this in the debugger by examining an instance of your UITableViewCell:

let cell = dequeueReusableCellWithIdentifier(MyCell.cellIdentifier, forIndexPath: indexPath) as! MyCell

// check cell.textLabel here in the debugger. should be nil.

cell.textLabel.text = "test"   // creates textLabel via lazy initialization 
+2
source

, - . , , , - , .

- , , , ( , , , ).

+1

Source: https://habr.com/ru/post/1598775/


All Articles