I would make a subclass of NSPersistentContainer and add a method to it for the network upate, inject that into the view controller an call the method. Since it is now in the container it will out-live the view controller, and you can also prevent the method being called twice, or queue them up.
Post
Replies
Boosts
Views
Activity
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/