Problems with ForEach, SwiftUI

Hi! I getting a lot of errors in ForEach and I don't know why at all.

Here is the code: In line 19

"Generic struct 'ForEach' requires that 'Artwork' conform to 'RandomAccessCollection'"

Thanks! Any help would be deeply appreciated!

Code:

Model:

ViewModel:

Answered by Claude31 in 742280022

Add:

ForEach(artwork, id: \.self)
Accepted Answer

Add:

ForEach(artwork, id: \.self)

your view model is publishing an array (a random access collection of artworks), but your ArtworkGridView declares a single var artwork: Artwork . You're asking ForEach to iterate over something that isn't a collection.

Problems with ForEach, SwiftUI
 
 
Q