Recall & Review
beginner
What is the purpose of the ObservableObject protocol in SwiftUI?
It allows a class to announce changes to its data so that SwiftUI views can update automatically when the data changes.Click to reveal answer
beginner
Which property wrapper is used inside an
ObservableObject to mark properties that trigger view updates?The
@Published property wrapper marks properties that, when changed, notify views to refresh.Click to reveal answer
intermediate
How do you connect an
ObservableObject to a SwiftUI view to listen for changes?Use the
@StateObject or @ObservedObject property wrapper in the view to subscribe to the ObservableObject.Click to reveal answer
beginner
What happens if you update a
@Published property inside an ObservableObject?All SwiftUI views observing that object will automatically refresh to reflect the new data.
Click to reveal answer
intermediate
Can structs conform to
ObservableObject protocol? Why or why not?No, because <code>ObservableObject</code> requires a class type to provide reference semantics and support change notifications.Click to reveal answer
Which keyword marks a property inside an ObservableObject to notify views when it changes?
✗ Incorrect
The @Published property wrapper marks properties that trigger view updates when changed.
Which property wrapper should you use in a SwiftUI view to subscribe to an ObservableObject that you create inside the view?
✗ Incorrect
@StateObject is used when the view owns the ObservableObject and manages its lifecycle.
What protocol must a class conform to in order to notify SwiftUI views about data changes?
✗ Incorrect
ObservableObject protocol allows a class to broadcast changes to its data.
If you want multiple views to share the same ObservableObject instance, which property wrapper is best to use?
✗ Incorrect
@EnvironmentObject allows sharing a single ObservableObject instance across many views.
Can a struct conform to ObservableObject protocol?
✗ Incorrect
ObservableObject requires reference semantics provided by classes, so structs cannot conform.
Explain how ObservableObject and @Published work together to update SwiftUI views.
Think about how a class tells views to refresh when its data changes.
You got /4 concepts.
Describe the difference between @StateObject and @ObservedObject when using ObservableObject in SwiftUI views.
Consider who creates and manages the ObservableObject instance.
You got /4 concepts.