Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
iOS Swift - Local Data Persistence
What is wrong with this code snippet?
@Model class Task { var title: String; let done: Bool }
let task = Task(title: "Read book", done: false)
task.done = true
AClass must be a struct to modify properties
BCannot assign to property of a let constant
CMissing @State annotation
D@Model classes cannot have Bool properties
Step-by-Step Solution
Solution:
  1. Step 1: Identify let constant usage

    The property done is declared with let, making it immutable.
  2. Step 2: Understand property mutation rules

    You cannot change let properties in a @Model class.
  3. Final Answer:

    Cannot assign to property of a let constant -> Option B
  4. Quick Check:

    let property is immutable [OK]
Quick Trick: Use var for @Model properties you want to modify, not let [OK]
Common Mistakes:
  • Trying to mutate let properties
  • Confusing @Model with @State
  • Thinking classes must be structs to mutate

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes