~/talk

Data flow in SwiftUI - from @State to @Observable...

Talkat #Pragma Conference 2023 · 2023-10-05..10-06· [swift, ios]
slides:none on file

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

  1. 0:00Introduction
  2. 1:31From @State to @Observable
  3. 3:38State and value types
  4. 5:27Moving controller code out
  5. 7:14Why views don’t update
  6. 9:04Combine’s role and limits
  7. 10:09Introducing @Observable
  8. 11:14Macro expansion details
  9. 14:08Computed properties and dependencies
  10. 15:33Separating model from controller
  11. 17:00Making model observable
  12. 17:44Non-observable controller
  13. 18:47withObservationTracking explained
  14. 21:14How SwiftUI tracks changes
  15. 22:40Passing controller to view
  16. 24:26Binding to observable model
  17. 25:08Slider binding demo
  18. 27:17Summary and future
  19. 28:23Q&A: Migration concerns
  20. 31:38Q&A: Reference vs value types
  21. 34:10Q&A: @State vs @StateObject
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.