如何获得 Core Data 列的平均值?
如果我有以下 NSManagedObject,如何获得 number1
值的平均值和 number2
值的平均值?
@interface Log : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * number1;
@property (nonatomic, retain) NSNumber * number2;
谢谢:D
If I have the following NSManagedObject, how can I get the average of values for number1
and the average of values for number2
?
@interface Log : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * number1;
@property (nonatomic, retain) NSNumber * number2;
Thanks :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用集合运算符
@avg
。假设您已经提取了
Log
对象并将生成的NSSet存储在中日志
。然后您可以简单地说:@avg
是可与关键路径中的集合一起使用的少数运算符之一。其他一些是@max
、@min
和@sum
。Use the collection operator
@avg
.Let's say you've already done a fetch for your
Log
objects and stored the resulting NSSet inlogs
. Then you can simply say:@avg
is one of a small handful of operators that you can use with collections in key paths. A few others are@max
,@min
, and@sum
.