~/talk

Building (and testing) custom property wrappers in SwiftUI

Talkat SwiftLeeds 2022 · on Thursday, 2022-10-20· [swift, testing]
slides:none on file

Builds a custom SwiftUI property wrapper that uses DynamicProperty to pull a URLSession from a custom EnvironmentKey, delegates loading to an ObservableObject data loader (held as a StateObject), and exposes results via the wrapper’s wrappedValue. Faces pitfalls: wrapper must be a struct, update() runs before body, and naive updates cause 3–4 duplicate network calls; solved by moving loading state into a class loader and using published properties. Tests use a UIHostingController and a PassthroughSubject to assert non‑empty posts.

AI-written summary · about

  1. 0:00Introduction and speaker intro
  2. 1:09What are property wrappers?
  3. 4:17SwiftUI’s special needs
  4. 6:43Building custom wrappers
  5. 8:46Property wrapper basics
  6. 10:09Dynamic Property protocol
  7. 12:15First working prototype
  8. 13:41Why it still doesn’t work
  9. 14:27Fixing with structs
  10. 16:10Separating state and logic
  11. 18:58Final architecture
  12. 20:02Dynamic Property recap
  13. 21:24Fitting into architecture
  14. 22:28Testing property wrappers
  15. 27:43Summary and takeaways
  16. 28:47Q&A session
~/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.