How is it possible that I can conform to a protocol requiring a synchronous getter and also mark the concrete property as @MainActor at the same time?
protocol MyProtocol {
var syncStuff: String { get }
}
class MyClass: MyProtocol {
var x = "sdfgsdfgd"
@MainActor
var syncStuff: String {
return x
}
}
Task.detached {
let instance: MyProtocol = MyClass()
let x = instance.syncStuff
print(x)
let instance2 = MyClass()
let y = await instance2.syncStuff
print(y)
}
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
In Swift 6 mode, functions with this kind of mismatch (sync requirement vs. @MainActor implementation) are flagged as errors. But for property getters, this compiles and runs without error.