actors, SwiftUI and @Published

Hi,

is there a way that an actor can have a @MainActor @Published annotated property which is then consumed by a SwiftUI View "as usual"?

Currently this:

@Published @MainActor public private(set) var state: State = .initial

gives me the following error when trying to access it from with a SwiftUI View: "Actor-isolated property '$state' can only be referenced from inside the actor"

I guess I understand where the error is coming from, but I wonder if there's a way to publish properties from actors and be able to make sure they are updated on the main thread by annotating them with @MainActor.

I have the same, a @MainActor @Published inside a actor (class) and I don't have any problem to use it from SwiftUI.

Maybe the problem is where are you using it. If you are inside another actor, you should probably call it using MainActor.run {} or something like that. (sorry, I'm still learning, that's why I'm not entirely sure)

actors, SwiftUI and @Published
 
 
Q