Data flow in SwiftUI - from @State to @Observable...
summary
Explains migrating SwiftUI state from @State/@StateObject and Combine to the iOS 17 @Observable macro, showing exactly what code the macro synthesizes (underscore storage, an observation registrar, and access/mutation hooks) and which parts actually notify views. Demonstrates that withObservationTrackingOnChange reports one step behind, that observable objects must be classes (models can’t be structs), and that two-way UI binding uses the new bindable mechanism to connect a Slider to a model’s Double. Claims Combine still works but observable is Apple’s future.
AI-written summary · about
chapters (21)
- 0:00Introduction
- 1:31From @State to @Observable
- 3:38State and value types
- 5:27Moving controller code out
- 7:14Why views don’t update
- 9:04Combine’s role and limits
- 10:09Introducing @Observable
- 11:14Macro expansion details
- 14:08Computed properties and dependencies
- 15:33Separating model from controller
- 17:00Making model observable
- 17:44Non-observable controller
- 18:47withObservationTracking explained
- 21:14How SwiftUI tracks changes
- 22:40Passing controller to view
- 24:26Binding to observable model
- 25:08Slider binding demo
- 27:17Summary and future
- 28:23Q&A: Migration concerns
- 31:38Q&A: Reference vs value types
- 34:10Q&A: @State vs @StateObject
related talks
35mSpeeding Up SwiftUI with Observable
49mWhy SwiftUI?
41mYour Life With (and Without) Observation
42mThe Evolution of Presentation Patterns in SwiftUI
19mSwiftUI Data Flow with Redux
40mFunctional iOS Architecture in the SwiftUI Era
21mSwiftUI & Redux
47mExploring Key Practices of Observation and SwiftData in New Application Development
