I’m curious, how can we push state changes from an actor out to SwiftUI? For instance, if I made an actor like this:
actor RandomTicker {
func start() async {
while true {
try! await Task.sleep(for: .seconds(Int.random(in: 1...4)))
// Do something here
}
}
}
Ideally, I’d like to be able to change a State variable or object where it says // Do something here
, but I’m not sure how to do so. All the example code I’ve seen is going the other way (ie data being pulled from the actors by the UI, rather than being pushed from the actor). Is there a well-tested solution for this?
1