Bird
0
0

Identify the error in the following Swift code:

medium📝 Debug Q6 of 15
Swift - Variables and Constants

Identify the error in the following Swift code:

typealias Score = Int
let playerScore: Score = "100"
ACannot assign a String to an Int alias
Btypealias syntax is incorrect
CVariable name cannot be Score
DMissing semicolon after declaration
Step-by-Step Solution
Solution:
  1. Step 1: Check typealias and variable type

    Score is an alias for Int, so playerScore must be an integer.
  2. Step 2: Analyze assigned value

    Assigning a string "100" to an integer type causes a type mismatch error.
  3. Final Answer:

    Cannot assign a String to an Int alias -> Option A
  4. Quick Check:

    Type mismatch error = assigning wrong type [OK]
Quick Trick: Alias type must match assigned value type exactly [OK]
Common Mistakes:
  • Assigning string to Int alias
  • Thinking typealias changes underlying type
  • Ignoring type mismatch errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes