Bird
0
0

Which of the following is the correct syntax for multiple optional binding in Swift?

easy📝 Syntax Q12 of 15
Swift - Optionals

Which of the following is the correct syntax for multiple optional binding in Swift?

if let a = optionalA, let b = optionalB {
    // code
}
Aif let a = optionalA, let b = optionalB { }
Bif let a = optionalA; let b = optionalB { }
Cif let a = optionalA && let b = optionalB { }
Dif let a = optionalA or let b = optionalB { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct separator for multiple bindings

    In Swift, multiple optional bindings in an if let statement are separated by commas.
  2. Step 2: Check each option's syntax

    if let a = optionalA, let b = optionalB { } uses commas correctly; others use invalid separators like semicolon, &&, or or.
  3. Final Answer:

    if let a = optionalA, let b = optionalB { } -> Option A
  4. Quick Check:

    Use commas to separate bindings [OK]
Quick Trick: Use commas, not semicolons or &&, between bindings [OK]
Common Mistakes:
  • Using semicolons instead of commas
  • Using logical operators like && or or
  • Missing commas between bindings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes