Post

Replies

Boosts

Views

Activity

Reply to Is it possible to use new Observation Framework with UIKit?
You can, here is a very simplified example // Apple documentation // https://developer.apple.com/documentation/observation @Observable class A { var name = "Nothing Here Yet" @ObservationIgnored var age = 0 } class ViewController: UIViewController { var a = A() var lbl: UILabel! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. setupLabel() track() a.name = "Hello World" } func track() { withObservationTracking { let _ = self.a.name } onChange: { Task { @MainActor [weak self] in self?.lbl.text = self?.a.name } } } func setupLabel() { lbl = UILabel(frame: CGRect(x: 135, y: 300, width: 300, height: 44)) lbl.text = a.name self.view.addSubview(lbl) } }
Jun ’23
Reply to Why is there no UIHostingView?
There is, only it is not a public API. _UIHostingView The underscore prefix means it is not public API. But it works if you try it out. However, I would not recommend using it, because there is a reason it is not public, and you will possibly bury mines in your code if you use it.
Jul ’23