I have a SwiftUI project using CoreData Database with a Product entity in it. It has 2 attributes, id, and barcode. Then I create a fetch request that seems to work but will result in an empty [Products].
When the view appears on screen I get the error
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1df9bda98) on the ForEach and no other information.
I tried to make it as simple as possible and I still have the problem. I tried to delete the xcdatamodel file entirely and recreate it and I keep have the problem.
private struct ProductList: View {
@FetchRequest(
entity: Product.entity(),
sortDescriptors: []
) var products: FetchedResults<Product>
var body: some View {
VStack {
List{
ForEach(products, id: \.id) { product in
ProductRow(product: product)
}
}
}
}
}
private struct ProductRow: View {
var product: Product
var body: some View {
Text(product.barcode ?? "No name given")
}
}