Which is the difference between @propertyWrapper
and @propertyDelegate
?
In all WWDC19 videos they talk about @propertyWrapper
, however all actual implementation use @propertyDelegate
(i.e SwiftUI - State); the compiler on Xcode 11 Beta
seems to accept both and ask for the exact same requirement:
@propertyDelegate struct A {
}
// Property delegate type 'A' does not contain a non-static property named 'value'
@propertyWrapper struct A {
}
// Property delegate type 'A' does not contain a non-static property named 'value'
Note that in both cases the compiler says "Property delegate".
Am I missing something or this is because they didn't decide yet which name to use?
TLDR; they are the same but you should use @propertyWrapper
.
As pointed out by @JosefDolezal on twitter https://twitter.com/josefdolezal/status/1137619597002248192?s=21, the name @propertyDelegate
was returned for revision by the core team https://forums.swift.org/t/returned-for-revision-se-0258-property-delegates/24080. The core team proposed multiple alternative namings, but because the proposal wasnt finalized before WWDC, they chose one of them to introduce this feature to the world.
So its very likely that @propertyDelegate
will be removed, and likely that @propertyWrapper
will stay, although this could still change during the ongoing evolution process.
In the second version of the @propertyWrapper
Swift Evolution proposal, there's a section outlining changes from the first reviewed version. At the top of this list, there we have it:
The name of the feature has been changed from "property delegates" to "property wrappers" to better communicate how they work and avoid the existing uses of the term "delegate" in the Apple developer community.
@propertyDelegate
has just been renamed to @propertyWrapper
. The name @propertyDelegate
will vanish soon, although it's still present in the SwiftUI
documentation as of 15/06/19.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With