AndyIbanez / andyibanez-com

Static website.
1 stars 0 forks source link

posts/understanding-property-wrappers-swift/ #22

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Understanding Property Wrappers in Swift • Andy Ibanez

https://www.andyibanez.com/posts/understanding-property-wrappers-swift/

francobellu-cap commented 3 years ago

Hi Andy,

you say that property wrappers are "a powerful feature in Swift that allow you to wrap behavior along with properties". And this is done through the creation of a new struct associated with the property wrapper. So isn't the same thing possible without property wrappers, just using a plain Capitalized struct ? Maybe the real added value of property wrappers is just the fact that we can use its computed property wrappedValue more conveniently. Don´t you think so?

AndyIbanez commented 3 years ago

Hi Andy,

you say that property wrappers are "a powerful feature in Swift that allow you to wrap behavior along with properties". And this is done through the creation of a new struct associated with the property wrapper. So isn't the same thing possible without property wrappers, just using a plain Capitalized struct ? Maybe the real added value of property wrappers is just the fact that we can use its computed property wrappedValue more conveniently. Don´t you think so?

No. It is one of their uses, but the most useful thing you can do is to store the values of variables in different (which is what SwiftUI does). A good example is a user defaults property wrapper or a keychain wrapper, but there's many more.