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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Verizon iPhone Summation of Proof shadrap iPhone 63 Jan 10, 2011 04:37 PM
Values into array from XML beesbane iPhone/iPad Programming 0 Dec 6, 2010 07:03 PM
Good Summation of Unanswered Questions: jazz1 iPad 8 Feb 27, 2010 09:40 PM
KVC Conventions? grimreaper1377 Mac Programming 1 Apr 24, 2009 01:19 PM
KVC simple path vs compound path HARDWARRIOR iPhone/iPad Programming 0 Apr 16, 2009 03:23 AM


All times are GMT -5. The time now is 03:15 PM.

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

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