@Observable ownership and passing
When working with an iOS 17 @Observable class in SwiftUI views, using "who owns it" and "how is it passed" as the criteria, when do you use @State, a plain property, @Bindable, and @Environment?
When working with an iOS 17 @Observable class in SwiftUI views, using "who owns it" and "how is it passed" as the criteria, when do you use @State, a plain property, @Bindable, and @Environment?
The view that creates it owns it with @State; a view that receives it and only reads uses let/var; a view that receives it and needs bindings ($) uses @Bindable; and sharing across the whole hierarchy uses .environment plus @Environment(Type.self).
SwiftUIMultiple choiceBasics
You're moving a SwiftUI app's ObservableObject code to @Observable. Select all the…
#observable #state #bindable #environment
SwiftUIShort answerIntro
A junior asks you why the screen doesn't update after they change a @State value in…
#observable #state
SwiftUIShort answerAdvanced
In SwiftUI, what does the iOS 17 @Observable macro give you over the older…
#observation #observable
SwiftUIMultiple choiceExpert
In this SwiftUI plus Observation code, when only store.count is incremented, select all…
#observation #observable