Post

Replies

Boosts

Views

Activity

Reply to @Observable and didSet?
When you mark a class as @Observable you can no longer use didSet because the macro converts it to a computed property. Trying to implement it should really show a warning "this code will never be reached" but it currently doesn't. Observation tracking can reach through computed vars, knowing that, wrapping an underscore observed var in your own computed var should allow you to do your didSet logic, e.g.: private var _test: String = "" // this has the observation logic public var test: String { get { _test // tracking reaches through test to _test } set { _test = newValue // do your didSet logic here } } } I cross posted this answer to my blog https://www.malcolmhall.com/2024/11/21/observable-and-didset/
9h