Avatar
(すいませんどうしても気になってしまいw) func runEscaping(_ operation: @escaping () -> Void) { Task.detached { print("3", Thread.isMainThread) // false operation() } } @MainActor final class Bar { func countUp() { print("1", Thread.isMainThread) // true runEscaping { print("2", Thread.isMainThread) // false Task { // ここはmain actor contextが引き継がれる print("4", Thread.isMainThread) // true👀 } } } } asyncを足すとtrueになる(MainActorにhopできる) func runEscaping(operation: @escaping () async -> Void) { Task.detached { print("3", Thread.isMainThread) // false await operation() } } @MainActor final class Bar { func countUp() { runEscaping { print("2", Thread.isMainThread) // trueになる👀 } } } (edited)