TIL `MainActor.assumeIsolated` and `@preconcurrency`
TIL MainActor.assumeIsolated
: What on earth is going on with awakeFromNib
?
The thing is, there are examples of
NSObject
subclasses that mixMainActor
and non-MainActor
methods. If the compiler were to treat all overrides as matching the isolation of its enclosing type, it would completely breakNSDocument
. Now, I want to be fair:NSDocument
is probably as close to pathological as you can get. It uses a custom concurrency system that is not based on GCD orOperationQueue
. And, it regularly mixes in main thread and background work, which is pretty much all configurable at runtime.
So how does this whole @preconcurrency
thing work?.
Remember, Swift concurrency is all about the type system. This means that definitions are hugely important to how things function. The
@preconcurrency
attribute alters how definitions are interpreted by the compiler. In general, it relaxes some rules that might otherwise make a definition difficult or even impossible to use.
The End of Singleton? Why Swift 6 Actors Are the Future of iOS Development
TIL CodeUA.