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








