I cannot figure out how to get this to work. I have a class (A
) that must be initialized on the main actor. An instance of that class is used as the default argument for another type's initializer:
@MainActor func testMainActor() {
class A {
// A's initializer must be on the main actor
@MainActor init() {}
}
class B {
// But A is a default parameter for a different initializer.
init(a: A = A()) {} // error: call to main actor-isolated initializer 'init()' in a synchronous nonisolated context
// Adding MainActor doesn't work either
@MainActor init(i: Int, a: A = A()) {} // error: call to main actor-isolated initializer 'init()' in a synchronous nonisolated context
}
_ = B()
}