1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

KVC Array Summation

Discussion in 'Mac Programming' started by hiddenpremise, Feb 13, 2009.

  1. macrumors regular


    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
    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,
  2. macrumors 68040


  3. macrumors member

    edit: delete plz

Share This Page