Bird
0
0

Identify the error in this Swift async code:

medium📝 Debug Q14 of 15
iOS Swift - Concurrency
Identify the error in this Swift async code:
func loadData() async -> String {
  return "Data"
}

let result = loadData()
print(result)
AAsync functions cannot return String
BMissing await keyword when calling async function
CFunction must be marked throws
DCannot print async function result
Step-by-Step Solution
Solution:
  1. Step 1: Check async function call

    Async functions must be called with await to get their result.
  2. Step 2: Identify missing await

    The code calls loadData() without await, causing a compile error.
  3. Final Answer:

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

    Call async with await = B [OK]
Quick Trick: Always use await when calling async functions [OK]
Common Mistakes:
  • Calling async functions without await
  • Thinking async functions can't return String
  • Assuming print can't show async results

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes