Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an async function named fetchData.
Swift
func fetchData() [1] {
// function body
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'await' instead of 'async' in the function declaration.
Forgetting to mark the function as async.
✗ Incorrect
The keyword async declares the function as asynchronous.
2fill in blank
mediumComplete the code to declare an async function that throws errors.
Swift
func loadData() [1] throws {
// function body
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Placing 'throws' before 'async'.
Using 'await' in the function declaration.
✗ Incorrect
The async keyword must come before throws in the function declaration.
3fill in blank
hardFix the error in the async function declaration.
Swift
func processData() [1] throws {
// function body
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'await' instead of 'async'.
Forgetting to include the
async keyword.✗ Incorrect
The async keyword must be placed before throws in the function declaration.
4fill in blank
hardFill both blanks to declare an async throwing function named fetchUser.
Swift
func fetchUser() [1] [2] { // function body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order to 'throws async'.
Using 'await' in the declaration.
✗ Incorrect
The correct order is async throws to declare an async function that can throw errors.
5fill in blank
hardFill all three blanks to declare an async function named downloadData that returns a String and can throw errors.
Swift
func downloadData() [1] [2] -> [3] { // function body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Void' as return type instead of 'String'.
Placing 'throws' before 'async'.
✗ Incorrect
The function is declared as async throws and returns a String.