And there is type-erased nonisolated AnyTransition that has all built-in transitions as static members (AnyTransition | Apple Developer Documentation). If I want to follow the pattern I hit a compiler error.
extension AnyTransition {
// Yields "Call to main actor-isolated initializer 'init(_:)'
// in a synchronous nonisolated context"
static var foo: AnyTransition { AnyTransition(Foo()) }
}
Neither AnyTransition extension nor the static members seem to be annotated with @MainActor while the actual built-in types seem to have main actor isolated initializers. So how are they able to return synchronously?
The only solution I can think of is that they are assuming an actor's execution context.
Is that it? Is it safe? I have encountered some crashes (unrelated to this) under com.apple.SwiftUI.AsyncRenderer domain recently so I'm not sure about such assumption.
In that case, the issue is static var foo: Foo inherits main actor isolation because it's defined in an extension of Transition (not Foo), which is Main Actor isolated.
However, since you don't access any property of Transition, you can simply opt-out of this Main Actor isolation inheritance and declare the static property as nonisolated:
Yeah I know. Either this or isolate my AnyTransaction static member to the main actor. But SwiftUI doesn't do that. All Transition types and members are main actor isolated while AnyTransition and its static members are nonisolated. So I was just curious how they are putting it together. Just to learn more about the new concurrency model.