What this thread does
Do first: put .receive(on: DispatchQueue.main) before the subscriber that mutates @Published state, then audit every independent callback that writes the same model.
Short answer
Diagnostic: Publishing changes from background threads is not allowed
As of November 2026, this card uses current SwiftUI/Combine documentation. Scheduler delivery changes the execution context of downstream messages (source.md)). Apple recommends isolating an ObservableObject model with @MainActor (WWDC21).
Choose / don't choose
- Combine chain: choose
receive(on:)before UI subscribers; avoid adding a separate dispatch inside every sink.
- Actor-isolated model: choose for UI-facing state ownership; keep expensive synchronous decoding outside that actor when possible (source).
Not for: list/detail navigation design; see swiftui-list-detail-navigationsplitview.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
receive(on:options:) | DispatchQueue.main or RunLoop.main before UI writes; options defaults to nil | Current Combine docs | source.md) |
decode(type:decoder:) | Decode response data before the main-scheduler hop; use the model type and JSONDecoder() | Current Foundation/Combine docs | source |
@MainActor | Annotate the UI-facing ObservableObject class; access isolated state through its actor | Current SwiftUI guidance | source |
MainActor.run | await MainActor.run { ... } for a state-write closure from asynchronous code outside the actor | Current Swift concurrency docs | source |
Order of operations
1. Fetch data, validate/extract the response, then decode(type:decoder:). Apple's pipeline example places decoding before main-queue delivery. 2. Apply receive(on: DispatchQueue.main) before both success-state and error-state mutations; write observable state in the downstream subscriber. Do not mutate it during earlier processing. 3. Isolate the owning model with @MainActor; bridge asynchronous callers through actor isolation. Legacy callbacks that do not participate in concurrency checking still need an explicit main-queue/actor boundary. 4. Audit every other writer. Luke Redpath's February 18, 2021 report traced the warning to a NWPathMonitor callback and moved its state write to the main queue.
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
| Background publication warning (symptom) | A background callback writes observable UI state | Move the write across the main boundary; check network-monitor callbacks as well as request completion | source |
Missing
- The linked source does not confirm: choose
DispatchQueue.main.asyncfor a UI write in a callback outside that chain; a downstream Combine operator cannot move it (source). - The linked source does not confirm: Runtime scheduler delivery and compiler actor isolation are separate obligations. (Neither linked page explicitly states this scheduler-versus-actor obligations comparison).
- The exact callback still writing in a particular app cannot be identified without its code; the network-monitor report is an example, not an app-specific diagnosis.
@Observabledoes not itself impose main-actor isolation; Philippe Hausler explains that separate synchronization responsibility in the November 2023 reply in a related topic.
Checked
2026-11-12; Current Combine receive, Foundation URL-session pipeline and MainActor references; Apple WWDC21 concurrency guidance; Luke Redpath's dated report and Philippe Hausler's forum explanation read. No application commands executed.
Started from a post by @Apple, packaged by the editor. Original post