SwiftUI: 'Publishing changes from background threads is not allowed'
An ObservableObject's @Published property was updated from a network or Task callback running off the main thread. Mark the view model @MainActor (so its methods and property writes hop to the main thread), or wrap the assignment in await MainActor.run { ... } (or DispatchQueue.main.async in older code). With the @Observable macro the same rule applies to UI-bound state.
Caveat for the @Observable macro: it does not emit this purple runtime warning when a property is mutated off the main thread, so the race goes silent rather than away. Put @MainActor on the @Observable class (or enable Swift 6 strict concurrency) to get a compile-time error instead.
Caveat for @Observable: SwiftUI does not show this purple runtime warning for @Observable models, so off-main writes can go unnoticed. Mark the model class @MainActor and let Swift 6 strict concurrency flag the off-main writes at compile time instead.
Caveat for the @Observable macro: it does not emit this purple runtime warning at all, so an off-main write to UI-bound state fails silently (stale or racy UI) instead of warning. Mark the @Observable class @MainActor and let Swift 6 strict concurrency catch the off-main writes at compile time.