【发布时间】:2019-11-23 00:33:58
【问题描述】:
我正在阅读 Apple 在 building lists and navigation 上的 SwiftUI 教程,但我似乎找不到任何有关此 List 初始化程序或 Array 类型的 identified(by:) 方法的文档:
struct LandmarkList: View {
var body: some View {
List(landmarkData.identified(by: \.id)) { landmark in
}
}
}
当我在 Xcode 中右键单击 List 初始化程序并单击 Jump to Definition 时,它会将我带到 this initializer 这是不正确的。当我对 identified(by:) 方法执行相同操作时,它会将我带到这个奇怪的文件,它只有 13 行并且没有提及 identified(by:) 方法:
我知道 Xcode 处于测试阶段,但我在哪里可以找到这些神秘代码的文档?到目前为止,教程已经很棒了,但我不确定 List 和 Array 在做什么。
【问题讨论】:
-
他们是swift 5.1引入的函数构建器,你真正想知道什么?
-
developer.apple.com/documentation/swift/collection/…,List 初始化程序是采用
() -> Content闭包的初始化程序。 -
@Sulthan 谢谢,我在任何地方都找不到
identified(by:)方法。至于List初始化器,为什么不需要我指定content参数名称? developer.apple.com/documentation/swiftui/list/3270227-init -
@RobJohansen 也许我弄错了。尝试写明确的
.init并跳转到那个。