在此视频中:https ://developer.apple.com/videos/play/wwdc2019/103/ ,以下代码片段显示在 15:30 左右:
...
ForEach(ContentSizeCategory.common.identified(by: \.self))
...
它有什么作用?self
指向哪里?当前对象 ( TraitCell_Preview
)?它甚至无法在我的计算机中编译,因为common
它不是ContentSizeCategory
. 我以为我以前在一次SwiftUI
谈话中看到过它(\.self
)。Keypath
不过,这并不是我在 Swift 中最好的东西。
我理解ForEach
的元素需要Identifiable
。self
(又名TraitCell_Preview
对吗?)只符合PreviewProvider
所以不符合Identifiable
(如果符合的私有_PreviewProvider
协议PreviewProvider
不符合Identifiable
,则不确定,因为我看不到代码)。
代码片段中有什么\.self
,它指向哪里?