When adopting Swift 6, it's common to have cases when @MainActor class needs to conform to a protocol that has no explicit isolation:
protocol A {
func foo()
}
class VC: UIViewController, A {
func foo() {} // Main actor-isolated instance method 'foo()' cannot be used to satisfy nonisolated protocol requirement
}
This case is covered in the official documentation. One of the solutions is to conform to a protocol with the @preconcurrency attribute.
But when we add new protocol B that inherits protocol A, the warning appears:
protocol A {
func foo()
}
protocol B: A {}
class VC: UIViewController, @preconcurrency B { // @preconcurrency attribute on conformance to 'B' has no effect
func foo() {}
}
Why is that? Is it expected behavior or a bug?
When we add a function to protocol B, the warning disappears:
protocol A {
func foo()
}
protocol B: A {
func bar()
}
class VC: UIViewController, @preconcurrency B {
func foo() {}
func bar() {}
}
How do you find out in which cases adding @preconcurrency to protocol conformance has no effect?