Bird
0
0

Which of the following is the correct way to declare an async function in Swift?

easy📝 Syntax Q12 of 15
iOS Swift - Concurrency
Which of the following is the correct way to declare an async function in Swift?
Afunc fetchData() async throws -> String {}
Basync func fetchData() -> String {}
Cfunc async fetchData() throws -> String {}
Dfunc fetchData() throws async String {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift async function syntax

    In Swift, async comes after the parameter list and before the return type.
  2. Step 2: Match options to correct syntax

    Only func fetchData() async throws -> String {} matches the correct syntax: func name() async throws -> Type {}.
  3. Final Answer:

    func fetchData() async throws -> String {} -> Option A
  4. Quick Check:

    Async keyword after () = C [OK]
Quick Trick: Async keyword goes after function parameters () [OK]
Common Mistakes:
  • Placing async before func keyword
  • Mixing async and throws order
  • Putting async after return type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes