What is projectedValue? Give a real example.
Mental model. The $ is a second door into the same wrapper, built for a different audience — bindings, publishers, references.
projectedValue is the value exposed through the $ prefix. The wrapper decides what it is:
@Published→$nameis aPublisher.@State/@Binding→$nameis aBinding.@Environment→ a read-only value projection.
Your own wrapper can project anything: a reference, an observable, a publisher with errors, or a test hook.
Common traps
- Assuming
$is always a binding. It is whatever the wrapper returns — often a publisher or a plain value. - Mutating through the projection and expecting the wrapped value to update when the wrapper does not implement that. The projection is a separate API; it only does what it is coded to do.
They might follow up with
- Why does
@Publishedproject a publisher instead of a binding? Because its job is change notification, not two-way editing. - Can you have both? Yes — a wrapper can expose a projection type that offers both a binding and a publisher.
Related questions
- 1.6.3 What is a property wrapper? Can you write a custom one?
- 1.6.5 Are property wrappers thread-safe? Is lazy?
← What is a property wrapper? Can you write a custom one? Are property wrappers thread-safe? Is lazy? →