Hello,
I have created a Core Data application which contains Order and CartProduct entities.
Order has one-to-many relationship with CartProduct and the inverse is to-one.
I add the products to the order, but there is a page where I want to display the products but looks like there is displayed only the last product.
In printProducts it prints the correct quantity of all the products, but in the list, only the quantity (and name) of the first product gets repeated (the number of products is correct)
Am I missing something on Core Data?
I have created a Core Data application which contains Order and CartProduct entities.
Order has one-to-many relationship with CartProduct and the inverse is to-one.
I add the products to the order, but there is a page where I want to display the products but looks like there is displayed only the last product.
Code Block @FetchRequest( entity: Order.entity(), sortDescriptors: [], predicate:NSPredicate(format: "status == %@", "ongoing") ) var orders: FetchedResults<Order> var body: some View { if(!orders.isEmpty) { GeometryReader {geometry in VStack(alignment: .leading){ Text("Ongoing order").padding().font(.largeTitle) List(orders[0].products!.array as! [CartProduct]){product in Text("\(product.quantity) * \(product.name!)") }.onAppear(perform: printProducts) } } } }
In printProducts it prints the correct quantity of all the products, but in the list, only the quantity (and name) of the first product gets repeated (the number of products is correct)
Am I missing something on Core Data?