- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
@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/
@propertyWrapper 和 @propertyDelegate 有什么区别?在所有 WWDC19 视频中,他们都在谈论 @propertyWrapper,但是所有实际实现都使用 @prope
我是一名优秀的程序员,十分优秀!