SwiftUI - 类型“[Color]”的值没有成员 'identified'
SwiftUI - Value of type '[Color]' has no member 'identified'
这是我的代码:
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)
}
}
}
}
但是我得到了错误:
Value of type '[Color]' has no member 'identified'
可能是什么原因?我正在使用 Xcode 11 beta 5。
对于Xcode 11 Beta 5 和以上,使用:
ForEach(colors, id: \.self)
对于 Xcode 11 Beta 4 和 以下 使用:
ForEach(colors.identified(by: \.self))
这是我的代码:
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)
}
}
}
}
但是我得到了错误:
Value of type '[Color]' has no member 'identified'
可能是什么原因?我正在使用 Xcode 11 beta 5。
对于Xcode 11 Beta 5 和以上,使用:
ForEach(colors, id: \.self)
对于 Xcode 11 Beta 4 和 以下 使用:
ForEach(colors.identified(by: \.self))