According to this old thread
the answer is no. But I never understood why.
In the old world. It was always required that you make changes to @Published properties on the main thread. In fact compiler would complain.
In the main world, can you just update that in the background thread? And then SwiftUI take cares of refreshing the views on the main thread? So I guess that begs that question, why did it used to require it for @Published?
Furthermore, I have recently gotten new crashes when update is done from background but I can't be sure it's related:
For example I have the following, and the crash is as follows:
@Observable
class PlanViewModel {
var stagingPlan: Plan?
func savePlan() async {
//some code here....
stagingPlan = nil //crash
}
}
Is this issue potentially related to main thread? Should I do that assignment forcefully on main thread?
call stack 1
call stack 2
call stack 3
I dont know how to troubleshoot this further as xcode doesnt provide me any info other than that one red line