I have a simple piece of code:
struct ContentView: View {
var body: some View {
Text("Hello world!")
.task {
await myAsyncFunc()
}
}
private func myAsyncFunc() async {}
}
This compiles completely fine. However, if I replace the task with this:
.task(myAsyncFunc)
It doesn't work, and gives me the error below:
Converting non-sendable function value to '@Sendable () async -> Void' may introduce data races
Why is this, and how can I fix it?