Avatar
Concurrencyの話題だとこんなPitchが出てましたね。@MainActorのメソッドをawaitなしで呼べるようにする。noasyncなのでsyncコードからのみ呼び出し可能。 @MainActor func updateUI(_ diffs: [Difference]) { /* ... */ } public extension SingleUpdate { func apply() { generateDiffs(from: rawContent, on: DispatchQueue.main) { diffs in unsafeAssumeOnMainActor { updateUI(diffs) } } } // ... } https://forums.swift.org/t/pitch-unsafe-assume-on-mainactor/63074 実行時に本当にMainActorかのチェックもしてくれるみたいです。 The unsafeAssumeOnMainActor function is a nonisolated, non-async function that accepts a @MainActor closure. First, unsafeAssumeOnMainActor performs a runtime test to see if it has been called on the MainActor. If the assumption was wrong, the program will emit a diagnostic message and can either continue executing the closure or abort execution. (edited)