Bird
0
0

Find the mistake in this code snippet:

medium📝 Debug Q7 of 15
Swift - Data Types
Find the mistake in this code snippet:
typealias Coordinates = (x: Int, y: Int)
let point: Coordinates = (x: 10, y: "20")
Atypealias cannot be used for tuples
BTuple cannot have named elements
Cy should be Int, not String
DNo mistake, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Analyze tuple typealias

    Coordinates expects x and y as Int values.
  2. Step 2: Check assigned tuple values

    The value for y is a String "20", which mismatches the expected Int type.
  3. Final Answer:

    y should be Int, not String -> Option C
  4. Quick Check:

    Tuple element types must match alias definition [OK]
Quick Trick: Tuple element types must exactly match alias [OK]
Common Mistakes:
  • Assigning wrong types to tuple elements
  • Thinking tuple elements can't be named
  • Assuming typealias disallows tuples

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes