I tried to list a array of struct with swiftUI.
import SwiftUI
struct User: Codable {
var id: UUID
var name: String
}
struct MyView: View {
@State private var users = [User]()
var body: some View {
List(users, id: \.id) { // Type '_' has no member 'id'
VStack(alignment: .leading) {
Text($0.name)
.font(.headline)
}
}
}
...
}
But the compiler report a error show that User struct has no id property.
var id: UUID()and the User struct ought to conform toIdentifiableas well