As for now, it goes well, but I'm stuck at the moment. The problem is, i have a NSMutableArray that contains NSNumber. I want to use @avg, @min and like.
My code doesn't work. It shows 0. So, what's the problem here?
CODE
srand(time(NULL));
for(int i=0;i<10;i++){
NSNumber* number = [[NSNumber alloc] initWithInt:(rand()%80)];
NSLog(@"%d",[number intValue]);
[array addObject:number];
}
NSNumber* avg = [array valueForKeyPath:@"@avg"];
NSLog(@"%s:%d","AverageValue",avg);
NSNumber* count = [array valueForKeyPath:@"@count.intValue"];
NSLog(@"%s:%d","Count",count);
for(int i=0;i<10;i++){
NSNumber* number = [[NSNumber alloc] initWithInt:(rand()%80)];
NSLog(@"%d",[number intValue]);
[array addObject:number];
}
NSNumber* avg = [array valueForKeyPath:@"@avg"];
NSLog(@"%s:%d","AverageValue",avg);
NSNumber* count = [array valueForKeyPath:@"@count.intValue"];
NSLog(@"%s:%d","Count",count);
I've used two different syntaxes for this. First, i tried the count.intValue, and then i tried only avg, without anything (how's that supposed to work, i do not know, it was nothing but wild guessing on my side here. Idiotic, i know.).
So, how it should look like here?