Bird
0
0

Why does declaring a collection with let in Swift NOT prevent modification of its contents, even if the collection is a class instance?

hard📝 Conceptual Q10 of 15
Swift - Collections
Why does declaring a collection with let in Swift NOT prevent modification of its contents, even if the collection is a class instance?
ABecause <code>let</code> makes the reference constant, not the object itself
BBecause Swift copies the collection on declaration with let
CBecause <code>let</code> disables all methods on the collection
DBecause collections declared with let are automatically frozen
Step-by-Step Solution
Solution:
  1. Step 1: Understand what let does in Swift

    let makes the variable reference constant, meaning it cannot point to a different object.
  2. Step 2: Recognize difference between reference and object mutability

    If the collection is a class instance, its internal state can still change unless the class restricts it.
  3. Final Answer:

    Because let makes the reference constant, not the object itself -> Option A
  4. Quick Check:

    let affects reference, not object mutability [OK]
Quick Trick: let fixes reference; object mutability depends on type [OK]
Common Mistakes:
  • Thinking let freezes the object itself
  • Assuming let disables all methods
  • Confusing copy behavior with let

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes