DEV Community

Liang Wang
Liang Wang

Posted on

Task: try or no try

In the ContentView I have this modifier added to fetch data:
.task {
await viewModel.fetchData()
}

It works great! But if I accidentally added a try before await, Xcode will complain about Invalid conversion from throwing function of type '@Sendable () async throws -> ()' to non-throwing function type '@Sendable () async -> Void'

Don't try if it is NOT needed.

Top comments (0)