MainActor.assumeIsolated, Preconcurrency, and Isolated Conformances
mjtsai.com·6h
Flag this post

Fatbobman:

As Swift 6 gradually gains adoption, this problem becomes increasingly prominent: developers want to benefit from the concurrency safety guarantees provided by the Swift compiler, while struggling with how to make their code meet compilation requirements. This article will demonstrate the clever use of MainActor.assumeIsolated in specific scenarios through an implementation case with NSTextAttachmentViewProvider.

[…]

We seem to be caught in a dilemma: we need to construct UIHostingController in MainActor, yet we cannot assign the constructed view (UIView) to self.view within MainActor.

[…]

Looking at MainActor.assumeIsolated’s signature, we can see that this API provides a `Ma…

Similar Posts

Loading similar posts...