0
0
Swiftprogramming~10 mins

Async functions declaration in Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Athrows
Bsync
Cawait
Dasync
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'await' instead of 'async' in the function declaration.
Forgetting to mark the function as async.
2fill in blank
medium

Complete 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'
Aawait
Basync
Csync
Dtry
Attempts:
3 left
💡 Hint
Common Mistakes
Placing 'throws' before 'async'.
Using 'await' in the function declaration.
3fill in blank
hard

Fix the error in the async function declaration.

Swift
func processData() [1] throws {
    // function body
}
Drag options to blanks, or click blank then click option'
Aasync
Bsync
Cawait
Dtry
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'await' instead of 'async'.
Forgetting to include the async keyword.
4fill in blank
hard

Fill 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'
Aasync
Bthrows
Cawait
Dsync
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order to 'throws async'.
Using 'await' in the declaration.
5fill in blank
hard

Fill 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'
Aasync
Bthrows
CString
DVoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Void' as return type instead of 'String'.
Placing 'throws' before 'async'.