Re: Copying, hash, and isEqual:
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.
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>) |