Skip to content

Instantly share code, notes, and snippets.

@hlung
Created September 25, 2022 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlung/5b29754979cb635926c529e00acd4663 to your computer and use it in GitHub Desktop.
Save hlung/5b29754979cb635926c529e00acd4663 to your computer and use it in GitHub Desktop.
for medium blog
import UIKit
class MyViewController: UIViewController {
var name: String = "" {
didSet {
print("name = \(name)")
testLabel.text = name // 2
}
}
lazy var testLabel: UILabel = { // 3, 7
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "hello"
label.centerXAnchor.constraint(equalTo: view.centerXAnchor) // 4, 9
label.centerYAnchor.constraint(equalTo: view.centerYAnchor)
print("testLabel = \(label)")
return label // 8, 10
}()
override func viewDidLoad() { // 5
super.viewDidLoad()
view.addSubview(testLabel) // 6
}
}
let viewController = MyViewController()
viewController.name = "Luke" // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment