Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - Value of type '[Color]' has no member 'identified'

Here is my code:

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)
            }
        }
    }
}

But I got the error:

Value of type '[Color]' has no member 'identified'

What could be the reason? I'm using Xcode 11 beta 5.

like image 444
Bagusflyer Avatar asked Aug 08 '19 06:08

Bagusflyer


1 Answers

For Xcode 11 Beta 5 and above, use:

ForEach(colors, id: \.self)

For Xcode 11 Beta 4 and below use:

ForEach(colors.identified(by: \.self))
like image 81
Mojtaba Hosseini Avatar answered Nov 15 '22 07:11

Mojtaba Hosseini