• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSNumber math?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSNumber math?


  • Subject: NSNumber math?
  • From: "Christopher Hickman" <email@hidden>
  • Date: Thu, 11 May 2006 10:32:46 -0400

I take it that NSNumber instances are immutable, given that I can't find any
way to do math with them directly.

For example, this:

/* code snippet 1 */
int x = 1;
int y = 2;
int z;

z = x+y; //z == 3
/* end code snippet */

When using NSNumbers has to go to the way more complex:

/* code snippet 2 */
NSNumber *x = [NSNumber numberWithInt:1];
NSNumber *y = [NSNumber numberWithInt:2];
NSNumber *z;

z = [NSNumber numberWithInt:[x intValue] + [y intValue]]; //z == 3 as
NSNumber
/* end code snippet */

z = x+y is an error for the second one, since that would just be pointer
math--not good ;)

Are there some methods for performing math on NSNumbers that I'm just not
seeing in the docs?  Something like -[NSNumber add:] or -[NSNumber
subtract:], etc.?  Or do I have to pull the scalars out of their comfortable
little wrappers each time I have to do some math?

Topher

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSNumber math?
      • From: "Keith Ray" <email@hidden>
    • Re: NSNumber math?
      • From: Thilo Ettelt <email@hidden>
  • Prev by Date: Re: malloc during selectAll -> crash
  • Next by Date: remove horizontal lines firstColumn ?
  • Previous by thread: Re: malloc during selectAll -> crash
  • Next by thread: Re: NSNumber math?
  • Index(es):
    • Date
    • Thread