@MainActor – The Rules! | Mobile Messages…
Summary
The Swift compiler will guarantee that main-actor-isolated code will only be executed on the main thread, using the same mechanism that ensures mutually exclusive access to other actors. The Swift compiler absolutely 100% does not guarantee that main-actor-isolated code will only be executed on the main thread. I have been banging on for ages about how Apple should document this critical part of Swift, but they haven’t. This one does at least generate a warning message This situation is very common whenever you have a delegate pattern and ObjC code This is a massively simplified example, but it is essentially what lots of Apple frameworks do. The Swift code here generates no warnings – but calls mainFunc on a background thread – Any Library/Framework with a delegate, or a block callback (possibly) This isn’t technically a separate case, but it is important enough to be worth emphasising.