, init , , . .
- , , . , updateView() viewWillAppear(). , , , , , . , . :
class MyViewController: UIViewController {
var product: Product {
didSet {
updateView()
}
}
@IBOutlet private weak var productNameLabel: UILabel!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
updateView()
}
private func updateView() {
guard isViewLoaded() else {
return
}
if let product = product {
productNameLabel.text = product.title
}
}
}
, , , , . , , . , , , :
class MyViewController: UIViewController {
var product: Product {
didSet {
loadViewIfNeeded()
productNameLabel.text = product.title
}
}
@IBOutlet private weak var productNameLabel: UILabel!
}