Bird
0
0

Find the problem in this Swift code snippet:

medium📝 Debug Q7 of 15
iOS Swift - Concurrency
Find the problem in this Swift code snippet:
func fetchValue() async -> Int {
  return 10
}

func process() async {
  let value = fetchValue()
  print(value)
}
AMissing await before fetchValue() call.
Bprocess() should not be async.
CfetchValue() cannot return Int asynchronously.
Dprint cannot output async values.
Step-by-Step Solution
Solution:
  1. Step 1: Check async function call

    Inside async process(), calling async fetchValue() must use await.
  2. Step 2: Identify missing await

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

    Missing await before fetchValue() call. -> Option A
  4. Quick Check:

    async calls require await [OK]
Quick Trick: Always await async function calls inside async functions [OK]
Common Mistakes:
  • Calling async function without await
  • Thinking async functions can be called like sync
  • Ignoring compiler errors about missing await

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes