ios – How to use receive(on:) for SwiftUI Observable objects


SwiftUI requires publishers to publish values on main thread, or else the values must be received on main thread using receive(on:options) by the observers. The former requires careful writing of Publisher code to run code that changes published values on @MainActor(which I have been following). But I wish to know about the second option, i.e. how can observers choose to receive values on main thread? So let’s say if I have something like this in SwiftUI view

   @EnvironmentObject private var store:Store

where Store confirms to ObservableObject, how can I use receive(on:options) for any @Published properties emitted by Store in my SwiftUI view?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img