Znajdź średnią NSMutableArray za pomocą valueForKeyPath

Obecnie staram się znaleźć kompaktowy sposóbśrednia macierz. Oczywistym rozwiązaniem jest zsumowanie macierzy, a następnie podzielenie przez liczbę elementów. Znalazłem jednak metodę na stronie dewelopera Apple, która twierdzi, że można to zrobić w prostszy sposób, używając valueForKeyPath. Jest to powiązane tutaj:

http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/KeyValueCoding/Articles/CollectionOperators.html

Oto przykład, nad którym obecnie pracuję, aby spróbować go uruchomić:

-(void)arrayAverager
{
   NSMutableArray *myArray = [NSMutableArray arrayWithCapacity:25];
   [myArray addObject:[NSNumber numberWithInteger:myValue]];
   NSNumber *averageValue = [myArray valueForKeyPath:@"@avg.self"];
   NSLog(@"avg  = %@", averageValue);

} 

Theproblem jest: zamiast uśredniać tablicę, wypisuje tylko elementy z tablicy 1 przez 1.

AKTUALIZACJA

-(void) pixelAverager

{
    //Put x-coordinate value of all wanted pixels into an array
    NSMutableArray *xCoordinateArray = [NSMutableArray arrayWithCapacity:25];
    [xCoordinateArray addObject:[NSNumber numberWithInteger:xCoordinate]];
    NSLog(@"avg = %@", [xCoordinateArray valueForKeyPath:@"@avg.intValue"]);
 }

questionAnswers(2)

yourAnswerToTheQuestion