Bird
0
0

Identify the error in this Swift code:

medium📝 Debug Q6 of 15
iOS Swift - Swift Language Essentials
Identify the error in this Swift code:
let city = "Paris"
city = "London"
AMissing semicolon after declaration
BType mismatch: expected String but found Int
CCannot assign to value: 'city' is a constant
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Analyze declaration

    city is declared with let, making it a constant.
  2. Step 2: Assignment attempt

    Trying to assign "London" to city is invalid because constants cannot be reassigned.
  3. Step 3: Compiler error

    The compiler will throw an error: "Cannot assign to value: 'city' is a constant".
  4. Final Answer:

    Cannot assign to value: 'city' is a constant -> Option C
  5. Quick Check:

    Constants declared with let cannot be reassigned [OK]
Quick Trick: let constants cannot be changed after initialization [OK]
Common Mistakes:
  • Assuming let variables can be reassigned
  • Confusing type mismatch errors with reassignment errors
  • Ignoring Swift's immutability rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes