iOS NSNumber math

xaphann

macrumors newbie
Original poster
Oct 22, 2011
11
0
Apparently my mind is shot and ready for the week... having an issue doing some basic math. I need to add up a bunch of NSNumber into a total amount doing this;
Code:
NSNumber *total = number1 + number2 + number3;
Is giving me an error "invalid operands to binary expression (nsnumber * and nsnumber *)"

Just a note number1, number2 and number3 are defined as NSNumbers in core data entity.

thanks
 

chown33

Moderator
Staff member
Aug 9, 2009
8,664
4,929
vertical
Objective-C isn't Java. You can't do arithmetic on objects that represent numbers.

Get the value from the NSNumber object (int, float, double, whatever), then do arithmetic, then rewrap it in an NSNumber if needed.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.