SwiftUI state ownership
In a SwiftUI product editing screen, the parent view owns the product model and a child view edits just the price field. Among @State, @Binding, and @Observable, which would you put where?
In a SwiftUI product editing screen, the parent view owns the product model and a child view edits just the price field. Among @State, @Binding, and @Observable, which would you put where?
The parent view holds the product model in @State, the child editing view borrows just the price field as $product.price through @Binding, and only when the model has to be shared with other screens do you lift it into an @Observable class that the view that created it holds with @State.
SwiftUIMultiple choiceIntro
You're building a SwiftUI settings screen. A child view SettingsRow with a toggle needs…
#state #binding
SwiftUIMultiple choiceIntro
Select all the correctly matched pairs of situation and SwiftUI property wrapper. (Assume…
#state #binding
SwiftUIShort answerAdvanced
When working with an iOS 17 @Observable class in SwiftUI views, using "who owns it" and…
#state #observation
SwiftUIShort answerBasics
A counter screen built in SwiftUI has increment, decrement, and reset buttons plus a…
#swiftui #state