在此视频中: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,它指向哪里?