I'm using the following to get an output of:
2013-06-06 11:44:27.325 [2570:907] Rating: 0
2013-06-06 11:44:27.326 [2570:907] Rating: 2
2013-06-06 11:44:27.327 [2570:907] Rating: 3
[rateQuery findObjectsInBackgroundWithBlock:^(NSArray *rateObjects, NSError *error)
{
if( !error )
{
NSLog(@"rateobject %@", rateObjects);
for (id item in rateObjects) {
int ratingVal = [[item objectForKey:@"Rating"] intValue];
NSLog(@"Rating: %d", ratingVal);
}
}
}
];
I'm looking to add the numbers to get a total and then divide by a count to get an average "rating".
I tried this, but obviously the syntax is incorrect. I think I need to use an NSArray instead of "item":
NSNumber *sum=[[item objectForKey:@"Rating"] valueForKeyPath:@"@sum.floatValue"];
NSLog(@"Rating Sum: %@", sum);
thanks for any help.