swift · note · architecture
When Not To Create a Property Wrapper
Context
Property wrappers are useful, but they are not automatically the right abstraction. If a plain stored property or helper function reads more clearly, that is usually the better choice.
The snippet
struct DraftNameEditor: View {
let title: String
let onReset: () -> Void
var body: some View {
Button(title) {
onReset()
}
}
}
Why this works
This keeps the surface area small. The view gets exactly what it needs: a value to display and an action to run. There is no wrapper just for the sake of abstraction.
Use plain values or closures when:
- the value is read-only
- the view should not own the data
- the behavior is simple and local
Avoid creating a wrapper when:
- it hides ownership instead of clarifying it
- the abstraction is only used once
- the wrapper would be more complex than the code it replaces
Takeaway: If a wrapper does not clarify the boundary, keep the code plain.