Bird
0
0

Which of the following is the correct syntax to declare a tuple with an Int and a String in Swift?

easy📝 Syntax Q12 of 15
Swift - Data Types
Which of the following is the correct syntax to declare a tuple with an Int and a String in Swift?
Alet person: (Int, String) = (25, "Alice")
Blet person = Int, String = (25, "Alice")
Clet person = Int: 25, String: "Alice"
Dlet person: Int, String = (25, "Alice")
Step-by-Step Solution
Solution:
  1. Step 1: Check tuple declaration syntax

    Correct tuple syntax uses parentheses with types inside, then assigns values in parentheses.
  2. Step 2: Validate each option

    let person: (Int, String) = (25, "Alice") correctly declares a tuple type and assigns matching values. Others have syntax errors or wrong format.
  3. Final Answer:

    let person: (Int, String) = (25, "Alice") -> Option A
  4. Quick Check:

    Tuple syntax = (Type1, Type2) = (value1, value2) [OK]
Quick Trick: Use parentheses for tuple types and values [OK]
Common Mistakes:
  • Omitting parentheses around types
  • Trying to declare types outside tuple parentheses
  • Using incorrect colon placement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes