Re: NSNumber increment
Re: NSNumber increment
- Subject: Re: NSNumber increment
- From: Alastair Houghton <email@hidden>
- Date: Sun, 8 Jul 2007 11:15:39 +0100
On 8 Jul 2007, at 06:27, Jeremy Rotsztain wrote:
What's the syntax for incrementing a NSumber stored in an array?
There isn't one. NSNumber does not provide mathematical operations.
Also, it's intended to be immutable, which lets the implementation
provide singleton implementations for common small numbers.
[[colorsListed objectAtIndex:22] objectAtIndex:1];
Do I have to replace that number with the object?
[colorsListed replaceObjectAtIndex:22 withObject:[[[colorsListed
objectAtIndex:22] objectAtIndex:1] intValue + 1]];
Well that's not quite right, but it's along the right lines. You want
[colorsListed replaceObjectAtIndex:22
withObject:[NSNumber numberWithInt:
[[colorsListed objectAtIndex:
22] intValue] + 1]];
If incrementing this number is a one-off, and doesn't happen terribly
often, this is probably OK. If you're doing it a lot, you might
consider using a C array, or---if you need it to be an NSObject for
some reason---either using an NSMutableData and accessing its buffer
as a C array, or rolling your own array object for this purpose.
I'm sure there are
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden