Swift: Why is my @MainActor code running in the background?

@MainActor was introduced introduced in Swift 5.5 by SE-0316 as a way to tell the compiler that certain code should always be run on the main thread. However, we have seen some cases where functions annotated with @MainActor were still being called on a background thread. This post explores what was happening, and how it …