【问题标题】:SwiftUI - Value of type '[Color]' has no member 'identified'SwiftUI - “[Color]”类型的值没有“已识别”成员
【发布时间】:2019-12-15 19:40:28
【问题描述】:

这是我的代码:

struct ContentView : View {
    let colors: [Color] = [.red, .green, .blue]

    var body: some View {
        VStack {
            ForEach(colors.identified(by: \.self)) { color in
                Text(color.description.capitalized)
                    .padding()
                    .background(color)
            }
        }
    }
}

但我得到了错误:

“[Color]”类型的值没有“identified”成员

可能是什么原因?我正在使用 Xcode 11 beta 5。

【问题讨论】:

  • identified 已弃用,请改用 id:\.self。

标签: swift xcode swiftui


【解决方案1】:

对于 Xcode 11 Beta 5 及以上,请使用:

ForEach(colors, id: \.self)

对于 Xcode 11 Beta 4 及以下,请使用:

ForEach(colors.identified(by: \.self))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 2021-09-02
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多