@MainActor
class A {}
class VC: UIViewController {
let foo: A
init() {
self.foo = A() // Error: Call to main actor-isolated initializer 'init()' in a synchronous nonisolated context
super.init(nibName: nil, bundle: nil)
}
@MainActor
init() {
self.foo = A() // Compiles
super.init(nibName: nil, bundle: nil)
}
init(_ void: Void = ()) {
self.foo = A() // Compiles
super.init(nibName: nil, bundle: nil)
}
}
I get that A()
should be called on a main-actor initializer, but why the first initializer doesn't inherit the @MainActor
from UIViewController
? and why the Void
parameter gets rid of the error (even with -warn-concurrency
)?
Note: if I annotate VC
with @MainActor
, I get the same error for the super.init
in the first initializer, and the third initializer still works.