Challenge - 5 Problems
Master of @Model
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Understanding @Model property wrapper usage
What is the primary purpose of using the @Model property wrapper in SwiftUI apps?
Attempts:
2 left
💡 Hint
Think about how data is stored and updated in SwiftUI apps.
✗ Incorrect
The @Model property wrapper is used to mark data models that SwiftUI manages automatically, including saving and updating them.
❓ ui_behavior
intermediate1:30remaining
Effect of @Model on UI updates
Given a SwiftUI view with a @Model property, what happens when a property inside the model changes?
Attempts:
2 left
💡 Hint
Consider how SwiftUI reacts to changes in observed data.
✗ Incorrect
@Model notifies SwiftUI about data changes, triggering UI updates automatically.
📝 Syntax
advanced2:00remaining
Correct syntax for defining a @Model struct
Which of the following code snippets correctly defines a Swift data model using @Model?
iOS Swift
Choose the correct code snippet:
Attempts:
2 left
💡 Hint
Remember @Model is applied to the whole struct, not individual properties.
✗ Incorrect
The @Model attribute is placed before the struct declaration. Properties inside should be vars to allow changes.
❓ lifecycle
advanced2:00remaining
Persistence behavior of @Model data
When you mark a struct with @Model, what happens to instances of this model when the app is closed and reopened?
Attempts:
2 left
💡 Hint
Think about what automatic persistence means for user data.
✗ Incorrect
@Model enables automatic persistence, so data remains available after app restarts.
🔧 Debug
expert2:30remaining
Identifying error with @Model usage
What error will occur if you define a @Model struct with a property marked as let instead of var?
iOS Swift
import SwiftUI
@Model
struct Note {
let content: String
}Attempts:
2 left
💡 Hint
Consider how @Model tracks changes to properties.
✗ Incorrect
@Model requires properties to be mutable so it can track and save changes. Using let causes a compile-time error.