Avatar
Avatar
shiz
@swift-5.7.3 import Foundation @MainActor func run(action: @escaping @Sendable () -> Void) async { print("1") print(Thread.isMainThread) action() } Task { @MainActor in // 追加 await run { print("action") print(Thread.isMainThread) } print("2") print(Thread.isMainThread) } RunLoop.main.run(until: Date().addingTimeInterval(0.3))
swift57 BOT 6/7/2022 8:57 AM
1 true action true 2 true