Posts

Showing posts with the label Projected Value

Understanding Property Wrappers Swift

Property Wrappers Property wrappers in swift help us to separate the code that manages the validation and the code that actually defines it. Code that defines the property var   userId :  Int Code that manages the storage @ UserIdentifier var   userId : Int @ UserIdentifier  is a custom way to manage the storage. Don't worry it will be more clear in some time, but my whole point was to clear the understanding on the difference between defining and managing a property (with the help of Property Wrapper).  Consider a use case of UserIdentifier: We want to have a userId which can take maximum up to 100 ids. If a user tries to set it to a value more than 100, it won't allow Provide a validation flag if value exceeds then 100. i.e true if any adjustments made or else false.  Think of this validation to be added at 5 different properties of different class . It would be very difficult to manage , may be write extension to handle this.  extension Int ...