Overview - WrappedValue and projectedValue
What is it?
In Swift, WrappedValue and projectedValue are parts of property wrappers, a feature that lets you add extra behavior to properties. WrappedValue is the actual value stored and accessed through the property. ProjectedValue is an optional extra value or functionality that the wrapper can provide, accessed with a special syntax. Together, they help manage how properties behave and interact in a clean, reusable way.
Why it matters
Without WrappedValue and projectedValue, adding extra behavior to properties would require repetitive code or complex patterns. They solve the problem of cleanly separating property logic from usage, making code easier to read, maintain, and reuse. This leads to safer and more expressive Swift programs, especially in UI frameworks like SwiftUI where state management is crucial.
Where it fits
Before learning this, you should understand basic Swift properties and functions. After this, you can explore SwiftUI state management, custom property wrappers, and advanced Swift features like Combine for reactive programming.