Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 13, 2009, 09:35 AM   #1
hiddenpremise
macrumors regular
 
Join Date: Jul 2008
Location: Somewhere between my imagination and reality
KVC Array Summation

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
__________________
MBP i7 | iPhone 4 | iPad
hiddenpremise is offline   0 Reply With Quote
Old Feb 13, 2009, 10:29 AM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
I know nothing about KVC, but maybe this helps?
http://developer.apple.com/documenta...0002176-178593

-Lee

Edit:
Looks like this will work:
Code:
NSLog(@"%@", [myArray valueForKeyPath:@"@sum.intValue"]);

Last edited by lee1210; Feb 13, 2009 at 10:42 AM.
lee1210 is offline   0 Reply With Quote
Old Feb 13, 2009, 10:40 AM   #3
MacRumors Guy
macrumors member
 
Join Date: Sep 2008
edit: delete plz
MacRumors Guy is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Want RAID Array Mufasa804 Mac Peripherals 4 Sep 25, 2013 04:29 PM
Array Containing Dictionaries ahan.tm iPhone/iPad Programming 2 Nov 18, 2012 10:31 AM
NSMutable Array Help AnonymousInUse iPhone/iPad Programming 12 Oct 11, 2012 03:46 PM
RAID Array help Lord Adama Mac Pro 3 Jun 5, 2012 10:27 PM

Forum Jump

All times are GMT -5. The time now is 03:46 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC