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
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
.