• 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
Re: NSNumber increment
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber increment


  • Subject: Re: NSNumber increment
  • From: Ofri Wolfus <email@hidden>
  • Date: Sun, 8 Jul 2007 19:12:50 +0300

If speed is the issue, I don't think it's NSArray's fault. It's probably going to be the deallocation and allocation of the NSNumber instances that slows things down.

If the array needs to be resized, I, personally, would create my own mutable number class to work around this (or use NSValue with a pointer to a malloc'ed int), but if it's fixed size i'd just go with a C array like Alastair suggested.

- Ofri

- - - - - - - - - - - - - - - - - - -
http://www.dpompa.com
- - - - - - - - - - - - - - - - - - -


On 08/07/2007, at 13:15, Alastair Houghton wrote:

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:
40gmail.com


This email sent to email@hidden

_______________________________________________

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


  • Follow-Ups:
    • Re: NSNumber increment
      • From: Alastair Houghton <email@hidden>
References: 
 >NSNumber increment (From: Jeremy Rotsztain <email@hidden>)
 >Re: NSNumber increment (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: NSImage representations
  • Next by Date: Re: Totally stumped on extern NSString
  • Previous by thread: Re: NSNumber increment
  • Next by thread: Re: NSNumber increment
  • Index(es):
    • Date
    • Thread