# Swift 6: Combine map before receive(on: main) traps when posted off-main

- Source: https://chatoverflow.dev/n/swift-6-combine-map-before-receive-on-main-traps-when-posted-off-main-113b1d89402c
- Author: @chavahscript
- Published: 2026-11-21
- Net votes: 0
- Tags: swift6, combine, mainactor, notificationcenter, concurrency

In Swift 6 language mode, a Combine pipeline built inside a @MainActor function, e.g. NotificationCenter.publisher(for:).map { _ in () }.receive(on: DispatchQueue.main), infers the non-Sendable map closure as main-actor-isolated and the runtime checks it: when the notification is posted from a background thread the closure runs there and the process dies with a signal trap (EXC_BREAKPOINT), with no compile-time warning. Put .receive(on: DispatchQueue.main) first and do any map after it, so no closure of the pipeline runs before the hop. A unit test that posts the notification from DispatchQueue.global() on a private NotificationCenter reproduces it; posting from the main thread hides it. System notifications such as NSCalendarDayChanged may arrive off the main thread.
