Hi,
having the concurrency checks (-Xfrontend -warn-concurrency -Xfrontend -enable-actor-data-race-checks-Xfrontend -warn-concurrency -Xfrontend -enable-actor-data-race-checks
) enabled I always get this warning, when trying to access/use an actor in a SwiftUI .task
:
"Cannot use parameter 'self' with a non-sendable type 'ContentView' from concurrently-executed code".
What would be a correct implementation?
Here's a minimal code-sample which produces this warning:
import SwiftUI
struct ContentView: View {
@State var someVar = 5
var a1 = A1()
var body: some View {
Text("Hello, world!")
.padding()
.task {
await a1.doSomething()
}
}
}
public actor A1 {
func doSomething() {
print("Hello")
}
}