• 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: Dictionary keyed by a few sparse integers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dictionary keyed by a few sparse integers?


  • Subject: Re: Dictionary keyed by a few sparse integers?
  • From: Andy Lee <email@hidden>
  • Date: Fri, 29 Oct 2010 08:12:00 -0400

On Oct 29, 2010, at 7:52 AM, Graham Cox wrote:
>
> On 29/10/2010, at 10:44 PM, Roland King wrote:
>
>> It should work the way you've done it in a NSDictionary.
>>
>> Yes the numbers created by +numberWithUnsignedInteger: are distinct objects (normally, if I use low numbers they actually aren't, one of Cocoa's little optimizations I guess), however they compare as equal with isEqual: or isEqualToNumber:
>>
>> NSDictionary uses isEqual: so it should find it with no issue.

Not only that, it copies its keys.  Although in this case -copy probably doesn't create a new object (since NSNumbers are immutable), in the general case you should code as if it does anyway.

>> I just threw together a 10 line program which does that, puts an entry into a dictionary keyed on an NSNumber representation of an NSUInteger and gets it out with another distinct NSNumber of the same NSUInteger, it finds it. I did also test in that case that the two NSNumbers were distinct, they were.
>
>
> Of course, you're quite right, which is why I thought it would work in the first place.
>
> Having put it back to not using the static array, it's now working fine! Gremlins....

Happens all the time.  Someone should really do a study on why putting code back the way it was fixes bugs, especially after one has posted to cocoa-dev. :)

--Andy

>
> OK, need to try and work out why this didn't work first time around...
>
> --Graham
>
>
>
>
> _______________________________________________
>
> 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

_______________________________________________

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: Dictionary keyed by a few sparse integers?
      • From: Graham Cox <email@hidden>
References: 
 >Dictionary keyed by a few sparse integers? (From: Graham Cox <email@hidden>)
 >Re: Dictionary keyed by a few sparse integers? (From: Roland King <email@hidden>)
 >Re: Dictionary keyed by a few sparse integers? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Dictionary keyed by a few sparse integers?
  • Next by Date: Re: Dictionary keyed by a few sparse integers?
  • Previous by thread: Re: Dictionary keyed by a few sparse integers?
  • Next by thread: Re: Dictionary keyed by a few sparse integers?
  • Index(es):
    • Date
    • Thread