NSNumber math?
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