Bird
0
0

Identify the error in the following Swift code using multiple optional binding:

medium📝 Debug Q14 of 15
Swift - Optionals

Identify the error in the following Swift code using multiple optional binding:

let a: Int? = 3
let b: Int? = 4

if let x = a let y = b {
    print(x + y)
}
AUsing wrong variable names
BMissing comma between bindings
COptionals cannot be unwrapped together
DMissing braces around if block
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of multiple optional binding

    Multiple optional bindings must be separated by commas in the if let statement.
  2. Step 2: Identify missing comma

    The code misses a comma between let x = a and let y = b, causing a syntax error.
  3. Final Answer:

    Missing comma between bindings -> Option B
  4. Quick Check:

    Separate bindings with commas [OK]
Quick Trick: Check commas between bindings carefully [OK]
Common Mistakes:
  • Forgetting commas between bindings
  • Assuming multiple bindings can be space-separated
  • Misplacing braces or parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes