After switching our iOS app project from Swift 5 to Swift 6 and publishing an update, we started seeing a large number of crashes in Firebase Crashlytics.
The crashes are triggered by NotificationCenter methods (post, addObserver, removeObserver) and show the following error:
BUG IN CLIENT OF LIBDISPATCH: Assertion failed: Block was expected to execute on queue [com.apple.main-thread (0x1f9dc1580)]
All scopes to related calls are already explicitly marked with @MainActor. This issue never occurred with Swift 5, but appeared immediately after moving to Swift 6.
Has anyone else encountered this problem? Is there a known solution or workaround?
Thanks in advance!
The Swift 6 language mode enables some main-actor checking [1] and you’re probably hitting that. This is a good thing, because previously you were just running main thread code off the main thread, and that can produce all sorts of problems that are much harder to debug.
It’s hard to offer specific advice without seeing the code that’s failing. Can you reproduce this in your office? If so, create a small test project that shows the issue and then post some snippets from that and a corresponding Apple crash report (see Posting a Crash Report for advice on how to get and post that).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] See SE-0423