How to use async and await in Swift projects
To use async await in Swift, wrap the code in a Task. If the function throws an error, use do-try-catch syntax within the Task.
To use async-await syntax without error handling, wrap the code in a task, as demonstrated in the snippet below.
This calls the function shown in the do-try-catch syntax example offered below.
Do-try catch syntax allows you to handle errors that can occur as an async-await request is carried out.
To make use of do-try-catch syntax, either wrap the code in a Task (as demonstrated in the basic use example), or make your function async as shown in the code below.
If you wish for the error to be passed on with the function, use throws. An example of throws is available in Apple's Meet StoreKit 2.