I keep the Model as a Published var in the ViewModel and Observe it from the View.
When the model process goes into a background thread, if you publish the model value, the Xcode thread checker will react.
Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive (on :)) on model updates.
Is issued.
@StateObject var viewModel = ViewModel()
class ViewModel: ObservableObject {
@Published var model = Model()
var thisValue:String {
return model.thisValue // I want to use this value in view
}
struct Model {
var thisValue:String = "value" // I want to change this value on background threads.
I'd like to know how to receive the model value in the main thread, but I didn't quite understand and asked a question.
I would be very happy if you could tell me.