Objective c 神奇记录:总和聚合

Objective c 神奇记录:总和聚合,objective-c,core-data,magicalrecord,Objective C,Core Data,Magicalrecord,我正在对实体进行聚合,代码是: NSPredicate *betweenInterval = [NSPredicate predicateWithFormat:@"(date >= %@) AND (date < %@)", [interval.start value], [interval.end value]]; NSNumber * nbPoints = [OMSPointsEventEntity MR_aggregateOperation:@"sum:" onAttri

我正在对实体进行聚合,代码是:

 NSPredicate *betweenInterval = [NSPredicate predicateWithFormat:@"(date >= %@) AND (date < %@)", [interval.start value], [interval.end value]];

 NSNumber * nbPoints = [OMSPointsEventEntity MR_aggregateOperation:@"sum:" onAttribute:@"nbPoints" withPredicate:betweenInterval];

 return [nbPoints intValue];
NSPredicate*betweenInterval=[NSPredicate谓词格式:@“(日期>=%@)和(日期<%@)”,[interval.start value],[interval.end value];
NSNumber*nbPoints=[OMSPointSevententy MR_聚合操作:@“sum:”onAttribute:@“nbPoints”,带谓词:betweenInterval];
返回[nbPoints intValue];
NB分数为零,我不知道为什么


提示:我的实体上的属性NbPoints是NSNumber,应该是int吗?

我不知道MR,但在标准跳线数据中,聚合函数必须以
@
开头。也许你应该在MR文档中查一下

...MR_aggregateOperation:@"@sum"... // ???
如果可以获得所有
PointsEvent
实体的数组,则可以在获取后自己计算:

NSNumber *sum = [fetchedObjects valueForKeyPath:@"@sum.nbPoints"]; 

至于属性数据类型,您的设置似乎是正确的:
int32
或类似的或
float
在核心数据模型中,
NSNumber
在您的
NSManagedObject
子类中。

我没有找到任何关于这方面的文档,我在这里找到了一些链接(函数代码:,官方github页面:),祝贺您决定使用未记录的框架。您是否尝试了第二种解决方案?是否需要[interval.start value]?我以为可以传入日期…另一件要检查的事情是确保没有聚合的谓词返回数据…您可能在不知道的情况下过滤掉了所有内容。如果我用这个谓词做MR_findall+[fetchedObjects valueForKeyPath:@“@sum.nbPoints”];我有我想要的那笔钱。[interval.start value]是我自己的类,它返回NSDate。