Bird
0
0

Given the enum and code below, what will be printed?

medium📝 Predict Output Q4 of 15
iOS Swift - Swift Language Essentials
Given the enum and code below, what will be printed?
enum Status {
  case ready(String)
  case waiting(Int)
}

let current = Status.waiting(5)
switch current {
case .ready(let message):
  print(message)
case .waiting(let count):
  print("Waiting count: \(count)")
}
AWaiting count: waiting(5)
Bready
CWaiting count: 5
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Identify enum case and associated value

    Variable current is assigned Status.waiting with value 5.
  2. Step 2: Analyze switch statement

    Switch matches .waiting case, extracts count as 5, prints "Waiting count: 5".
  3. Final Answer:

    Waiting count: 5 -> Option C
  4. Quick Check:

    Switch matches case and prints associated value [OK]
Quick Trick: Switch extracts associated values with let in cases [OK]
Common Mistakes:
  • Confusing case names
  • Printing enum case instead of value
  • Missing let keyword
  • Assuming no output from switch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes