NSNumber math

Discussion in 'iOS Programming' started by xaphann, May 25, 2012.

  1. xaphann macrumors newbie

    Oct 22, 2011
    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;
    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.

  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    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.
  3. xaphann thread starter macrumors newbie

    Oct 22, 2011
    oops never replied to this. That worked great thanks.

Share This Page