Bird
0
0

Given this code:

hard📝 Application Q9 of 15
iOS Swift - Concurrency
Given this code:
func fetchValue() async -> Int {
  return 5
}

func doubleValue() async -> Int {
  let val = await fetchValue()
  return val * 2
}

What will doubleValue() return when awaited?
A5
BError: Cannot await inside async function
C10
D0
Step-by-Step Solution
Solution:
  1. Step 1: Await fetchValue inside doubleValue

    The doubleValue() function awaits fetchValue() which returns 5.
  2. Step 2: Multiply awaited result by 2

    It returns 5 * 2 = 10 asynchronously.
  3. Final Answer:

    10 -> Option C
  4. Quick Check:

    Await inside async function works = 10 [OK]
Quick Trick: Async functions can await other async functions [OK]
Common Mistakes:
  • Thinking await is disallowed inside async functions
  • Returning original value without multiplication
  • Confusing return types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes