I'm getting a warning with this code and I don't understand how to fix it. I'm curious to know how to pass a function into the task modifier.
private func placeholderRHSView(for client: AppClient) -> some View {
Color.clear
.frame(width: 290, height: 290)
.task(load(client)) // Warning: Converting non-sendable function value to '@Sendable () async -> Void' may introduce data races
}
private func load(_ client: AppClient) -> () -> Void {
return {
Task {
do {
let apps = try await client.recent()
} catch {}
}
}
}
How should I re-structure this code to make it thread safe?