How to Use Async/Await with Swiftui in Swift 5.5

How can I use async/await with SwiftUI in Swift 5.5?

As per new informations in WWDC session Meet async/await in Swift
WWDC21, at 23m:28s this is now done using:

Task {
someState = await someAsyncFunction()
}

Screenshot from the session.

Image showing how to use an Async task on a sync context

Note that there are more ways to instantiate a task. This is the most basic. You can use Task.detached as well and both ways can get a priority argument.
Check both the Task docs and the session
Check Explore structured concurrency in Swift WWDC21 at around 23:05 (I recommend the whole session!) for more info.

Async/Await function without a return | Swift 5.5

This is what worked the best:

try await withUnsafeThrowingContinuation { (continuation: UnsafeContinuation<Void, Error>) in


Related Topics



Leave a reply



Submit