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