I'm trying to ForEach a 2D array based on this answer here:
SwiftUI ForEach get element AND index in 2d array
ForEach(0..<memesSplit.endIndex) { index in
ForEach(memesSplit[index], id: \.memeid){_ in
}
}
and get this warning:
Non-constant range: argument must be an integer literal
I looked it up and it means the app will crash because of "out of index" in case an item will be removed.
So how to do this correctly?
When I do what I've tried first:
ForEach(memesSplit) { arr in
ForEach(arr, id: \.memeid){ meme in
}
}
then I get this error:
Referencing initializer 'init(_:content:)' on 'ForEach' requires that '[MemeModel]' conform to 'Identifiable'
Based on the mentioned question I tried:
ForEach(self.memeModel.memesSplit) { arr in
ForEach(arr, id: \.memeid){ meme in
}
}
And couple other syntaxes but get all kind of other errors where I don't know what they mean
This is the model of the inner array:
struct MemeModel: Codable {
var memeid: Int
var title: String
var pic: String
var size: String
var userid: Int
var nickname: String
var commentcount: Int
var time: Int
var secondsago: Int
var checked: Int
var liked: Int
var disliked: Int
var saved: Int
var voteup: Int
var votedown: Int
}
and this is how I declare the 2D array:
@State private var memesSplit = [[MemeModel]]()