Peter Zhao
Peter Zhao

Reputation: 57

SwiftUI ForEach not working after recent update

I've been using ForEach for a while now, it has been working fine until I updated my Xcode a couple days ago, now it says "Generic parameter 'ID' could not be inferred". Anyone else experiences the same issue?

ForEach(dataArray) { data in
...
}

Upvotes: 2

Views: 1443

Answers (1)

iSpain17
iSpain17

Reputation: 3053

Anytime you get that error, you should just use the following overload of ForEach:

ForEach(0..<dataArray.count, id: \.self) { index in 
   //refer to your items as dataArray[index] inside ForEach
}

You get the error because your dataArray elements are not conforming to Identifiable protocol.

Upvotes: 7

Related Questions