Ios 使用核心数据制表数据-如何有效过滤?

Ios 使用核心数据制表数据-如何有效过滤?,ios,cocoa-touch,core-data,nspredicate,Ios,Cocoa Touch,Core Data,Nspredicate,我正在开发一个用于报告销售数据的应用程序。核心数据结构如下所示 Product <---->> SaleAggregate Customer <---->> SaleAggregate 每个客户都可以记录任意数量的产品的销售,我需要检索所有这些销售,以某种方式按产品对它们进行分组,然后显示每个SaleAgregate“Amount”以及相应的月份/年份 我可以轻松地检索具有NSPredicate的客户的所有销售聚合,以及销售给具有NSPredicate和@d

我正在开发一个用于报告销售数据的应用程序。核心数据结构如下所示

Product <---->> SaleAggregate
Customer <---->> SaleAggregate
每个客户都可以记录任意数量的产品的销售,我需要检索所有这些销售,以某种方式按产品对它们进行分组,然后显示每个SaleAgregate“Amount”以及相应的月份/年份

我可以轻松地检索具有NSPredicate的客户的所有销售聚合,以及销售给具有NSPredicate和
@distinctUnionOfObjects
的客户的所有独特产品,但我不太确定从这里走到哪里

该表是用UICollectionView实现的,但我不太确定在
cellForItemAtIndexPath
的正确单元格中放置正确值的逻辑应该是什么。是否只是在一个查询中检索每个SaleAggregate,然后使用NSPredicate为每个要显示的单元格筛选正确月份/年份的数组?我想应该有一个更聪明的方法

谢谢

这个怎么样

使用谓词和筛选可以为特定客户获得以下信息

ProductArray:
SalesAggreateDateArray:


如果我理解正确,SalesAggregate对象的一个例子有数量,比如说40是某个特定客户在特定月份购买的特定产品的数量?
ProductArray:
SalesAggreateDateArray:
if section ==0 
      row==0 --> "Product"
      rest of the rows --> [ProductArray objectAtIndex:indexPath.row]
else if row ==0
      sections --> [SalesAggregateDateArray objectAtIndex:indexPath.section]
else
       each cell --> [SalesAggregateAmountObjects filter with 
                                 date= date at row 0, indexPath.section and 
                                 product = product at section 0, indexPath.row]