I have a JSON from my backend which returns:
[
{
productId : 1
name: productA
},
{
productid: 2
name: productB
}
}
And on my SwiftUI project I have a model:
struct ProductModel: Identifiable, Codable, Hashable {
//var id = UUID()
var productId = Int
var name = String
}
In my View, when I do a foreach to present all the products coming from my JSON, I got a message saying my model needs to be Identifiable to be using the foreach.
That was the reason I created the var id = UUID() on my model. Now I dont have the foreach error message, however, I get the error:
Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "id", intValue: nil)
Shouldn't it be ok since I am creating the ID on my model ?
Thank you !