【问题标题】:SwiftUI List initializer with identified(by:)SwiftUI 列表初始值设定项,已识别(作者:)
【发布时间】: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 处于测试阶段,但我在哪里可以找到这些神秘代码的文档?到目前为止,教程已经很棒了,但我不确定 ListArray 在做什么。

【问题讨论】:

标签: swiftui swift5


【解决方案1】:

identified 现在不再使用。你可以试试下面的语法。

List{
    ForEach(landmarkData, id: \.id) { landmark in
       Text(landmark.placeName)
    }
}

【讨论】:

    猜你喜欢
    • 2021-02-13
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 2012-12-24
    • 2021-01-21
    • 2013-06-12
    • 1970-01-01
    相关资源
    最近更新 更多