• 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: Copying, hash, and isEqual:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copying, hash, and isEqual:


  • Subject: Re: Copying, hash, and isEqual:
  • From: "b.bum" <email@hidden>
  • Date: Sun, 6 Jun 2004 17:03:14 -0700

On Jun 6, 2004, at 4:43 PM, Marcel Weiher wrote:
On 6 Jun 2004, at 18:03, b.bum wrote:
id pool=[NSAutoreleasePool new];
id a=[MyObject new];
id result=@"Hello world!";
id dict=[NSMutableDictionary dictionary];
[dict setObject:result forKey:a];
result = [dict objectForKey:a];

But your keys are not the same!

You are using the plural "keys". I am only using a *single* key. I am storing something and retrievig it using not just a key that is somehow equivalent, but the *very same identical* key. Yet NSDictionary can't find the value. That's a bug! The fact that NSDictionary turns this into two keys is the bug.

OK. Fine... let me rephrase. "But the key is not the same!"

The bottom line is this:

- NS*Dictionary copies keys. It is documented as doing so and this is the intended behavior, by design.

- if object (A) and object (B) are to be used as a key in a dictionary, then -hash and -isEqual: need to be overridden accordingly.

Your implementation does not follow the second rule. Your key is not the *very same identical* key as you claim.

NS*Dictionary is working exactly as documented and as designed.

b.bum
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Copying, hash, and isEqual:
      • From: Marcel Weiher <email@hidden>
References: 
 >Ugly bug in Foundation, beware! (From: Ondra Cada <email@hidden>)
 >Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Ondra Cada <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Brent Gulanowski <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Alastair Houghton <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Ondra Cada <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Brent Gulanowski <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: "Louis C. Sacha" <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>)
 >Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!) (From: Nat! <email@hidden>)
 >Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!) (From: Marcel Weiher <email@hidden>)
 >Copying, hash, and isEqual: (From: "b.bum" <email@hidden>)
 >Re: Copying, hash, and isEqual: (From: Marcel Weiher <email@hidden>)

  • Prev by Date: Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
  • Next by Date: Re: Copying, hash, and isEqual:
  • Previous by thread: Re: Copying, hash, and isEqual:
  • Next by thread: Re: Copying, hash, and isEqual:
  • Index(es):
    • Date
    • Thread