• 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: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)


  • Subject: Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
  • From: Marcel Weiher <email@hidden>
  • Date: Mon, 7 Jun 2004 00:52:58 +0100

------------------------ dictbug.m ------------
#import <Foundation/Foundation.h>

@interface MyObject : NSObject <NSCopying>
{}
@end
@implementation MyObject
-copyWithZone:(NSZone*)zone
{
id copy=[[[self class] alloc] init];
return copy;
}
@end

When you copy the key here, you create a new object. *BUT* NSObject, and
therefore MyObject implements isEqual: as '==' so the copied key is not
equal anymore to the one you passed to the dictionary... Hence, you can
never retreive your object from the dictionary.

Yes, precisely. I am not sure why you (and everyone else??) think you have to explain this to me, because the sample code was constructed to exploit/show this. I thought this was obvious, but obviously not obvious enough.

You should either make a clever isEqual: implementation for MyObject, or
heed the recomendation from the documentation:

No, I should not have to work around NSDictionary's buggy implementation. Furthermore, what I consider -isEqual: is application-dependent.

Implement NSCopying by retaining the original instead of creating a new
copy when the class and its contents are immutable.

Who says the contents are immutable (just add an instance var...)

Cheers,

Marcel

--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
1d480c25f397c4786386135f8e8938e4
_______________________________________________
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: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
      • From: Patrick Machielse <email@hidden>
    • Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!)
      • From: "Louis C. Sacha" <email@hidden>
References: 
 >Re: NSDictionary design bug (was: Re: Ugly bug in Foundation, beware!) (From: Patrick Machielse <email@hidden>)

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