Recall & Review
beginner
What keyword do you use in Swift to declare an asynchronous function?
You use the
async keyword after the function's parameter list to declare it as asynchronous.Click to reveal answer
intermediate
How do you mark a Swift function that can throw errors and is asynchronous?
You place
async before throws in the function declaration, like func fetchData() async throws.Click to reveal answer
beginner
What is the purpose of declaring a function as
async in Swift?Declaring a function as
async means it can perform work that might take time without blocking the program, allowing other code to run while waiting.Click to reveal answer
beginner
Show the syntax of a simple async function in Swift that returns an integer.
Example:<br>
func getNumber() async -> Int {
return 42
}Click to reveal answer
intermediate
Can an async function in Swift be called like a normal function? Why or why not?
No, async functions must be called with
await because they might pause execution until the result is ready.Click to reveal answer
Which keyword is used to declare an asynchronous function in Swift?
✗ Incorrect
The
async keyword declares a function as asynchronous.How do you call an async function in Swift?
✗ Incorrect
You must use
await to call an async function because it might pause execution.What does the
async keyword indicate about a Swift function?✗ Incorrect
async means the function can pause and resume, allowing other code to run meanwhile.Which of these is a correct async function declaration in Swift?
✗ Incorrect
The correct order is
async before throws in the declaration.What must you add before calling an async function inside another async function?
✗ Incorrect
You use
await to wait for the async function to finish.Explain how to declare an async function in Swift and why you would use it.
Think about how async helps with waiting for tasks without stopping the whole program.
You got /4 concepts.
Describe the difference between calling a normal function and an async function in Swift.
Focus on what you add before calling an async function and why.
You got /4 concepts.