Issue with ForEach in SwiftUI
OK, I soon figured out the answer. Per the Apple's docs, the array elements must be Identifiable
, so this works…
var body: some View {
List {
ForEach(requests.identified(by: \.self)) { request in
RequestRow(request: request)
}
}
}
I'm sure I won't be the last person to have this problem, so I'll leave this here for future reference.
I have the same problem, but in my case Component
is a Protocol, so it can't be conformed to Identifiable
VStack {
ForEach(components.identified(by: \.uuid)) { value -> UIFactory in
UIFactory(component: value)
}
}
However, If I try something like this it works fine
VStack {
ForEach(components.identified(by: \.uuid)) { value -> UIFactory in
Text(value.uuid)
}
}