Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hiddenpremise

macrumors regular
Original poster
I have been able to use KVC to sum an array with objects that have an [NSNumber] as an instance variable. Can I sum just an array using KVC? My attempts so far have failed.
ie. This code will return an uncaught exception
Code:
NSArray *myArray = [NSArray arrayWithObjects:[NSNumber numberWithInt:5], [NSNumber numberWithInt:6], [NSNumber numberWithInt:7], nil];

NSLog(@"%@", [myArray valueForKeyPath:@"@sum"]);

I can easily sum an array of numbers using loops and several lines of code, but I am really trying to get a solid hold on KVC. Any help is appreciated :)

Thanks much,
-Whit
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.