For your consideration. Code like this:
Image(systemName: shoppingListProducts.contains(product) ? "checklist.checked" : "checklist.unchecked")
.foregroundStyle( shoppingListProducts.contains(product) ? Color.green : Color.red))
This code is just begging you to create a computed property. A computed property would allow you to declare exactly what you'd like to see in the view. Instead, you have this code that makes your team pause, and wonder.
Computed Property
This might be pseudocode.
// declare the icon -- this returns the properListIcon for your view.
var properListIcon: Image {
Image(systemName: shoppingListProducts.contains(product) ? "checklist.checked" : "checklist.unchecked")
}
Now, in your view code, you simply declare what you want to display. You want to display the properListIcon.
struct ProductCell: View {
// ... data model stuff....
var body: some View {
// ...snip....
properListIcon // <-- Note you're declaring what you want to see in the view. Tuck the logic into your data model.
// ...snip....
}
}
or... we can just give you the answer. Like this....