Difference between @propertyDelegate and @propertyWrapper
Asked Answered
G

2

4

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?

Gelatinize answered 8/6, 2019 at 23:10 Comment(0)
L
7

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.

Ludhiana answered 9/6, 2019 at 9:17 Comment(0)
G
2

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.

Glum answered 15/6, 2019 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.