Check out this comment for a more detailed explanation about how the Task initialiser Task { }
inherits its execution context from the local actor context.
On the macOS playground, you're not calling Task { }
on a specific actor such as MainActor
, so it will be run on a random background thread. However, one can presume that view modifiers in SwiftUI are run on the main thread, therefore on the MainActor
. And since Task { }
inherits the local actor context, its closure is also run on the main thread / MainActor
.