Bird
0
0

What is the issue with this Swift code?

medium📝 Debug Q6 of 15
iOS Swift - Concurrency
What is the issue with this Swift code?
func fetchData() async -> String {
  return "Info"
}

let data = fetchData()
print(data)
AThe function must be marked with throws.
BAsync functions cannot return String values.
CMissing await keyword when calling async function.
Dprint cannot be used inside async context.
Step-by-Step Solution
Solution:
  1. Step 1: Identify async call rules

    Async functions must be called with await to get their result.
  2. Step 2: Analyze code

    The code calls fetchData() without await, so it returns a Task or compiler error.
  3. Final Answer:

    Missing await keyword when calling async function. -> Option C
  4. Quick Check:

    Async calls require await [OK]
Quick Trick: Always await async function calls [OK]
Common Mistakes:
  • Calling async functions without await
  • Assuming async functions can't return values
  • Confusing throws with async

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes