SwiftUI: Publishing changes from background threads is not allowed; make sure to publish values from the main thread
An ObservableObject’s @Published property was updated from a background thread.
Seen on:
iOS
Meaning
URLSession callbacks, Combine pipelines without receive(on:), and Task.detached run off the main actor. Mark the view model @MainActor or hop to the main actor before assigning.
Common causes
- Assigning @Published inside URLSession/async callbacks
- Combine without .receive(on: DispatchQueue.main)
- Background Task updating UI state
⚡ Quick fix
- Annotate the view model with @MainActor
- Use await MainActor.run { … }
- Add .receive(on: DispatchQueue.main) to Combine pipelines
Detailed fix by platform
Swift
- swift
@MainActor final class ProfileModel: ObservableObject { @Published var user: User? func load() async { user = try? await api.fetchUser() } }
How to diagnose
- Thread — Where the assignment happens
- Annotations — @MainActor present?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in iOS
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026