gpt4 book ai didi

swift - @propertyDelegate 和@propertyWrapper 的区别

转载 作者:可可西里 更新时间:2023-11-01 00:26:54 32 4
gpt4 key购买 nike

@propertyWrapper@propertyDelegate 有什么区别?在所有 WWDC19 视频中,他们都在谈论 @propertyWrapper,但是所有实际实现都使用 @propertyDelegate(即 SwiftUI - State); Xcode 11 Beta 上的编译器似乎接受两者并要求完全相同的要求:

@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'

请注意,在这两种情况下,编译器都会说“属性委托(delegate)”

我是不是遗漏了什么,或者这是因为他们还没有决定使用哪个名称?

最佳答案

TLDR;它们是相同的,但您应该使用 @propertyWrapper

正如@JosefDolezal 在推特上指出的那样 https://twitter.com/josefdolezal/status/1137619597002248192?s=21 , 名称 @propertyDelegate 被核心团队返回修改 https://forums.swift.org/t/returned-for-revision-se-0258-property-delegates/24080 .核心团队提出了多个备选命名方案,但由于提案在 WWDC 之前尚未最终确定,他们选择了其中一个来向全世界介绍此功能。

因此 @propertyDelegate 很可能会被删除,而 @propertyWrapper 很可能会保留下来,尽管这在正在进行的演变过程中仍可能会发生变化。

关于swift - @propertyDelegate 和@propertyWrapper 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56510768/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com