On 2007-03-19 02:43:36 -0800 Richard Frith-Macdonald <[EMAIL PROTECTED]> wrote:


On 19 Mar 2007, at 10:24, Michael Gardner wrote:

To use a custom key type with NSMutableDictionary, I defined -hash and -isEqual: but not -copyWithZone:, since the NSDictionary docs say that
keys are retained rather than copied. But when I try to insert a key
of that type, I get an NSInvalidArgumentException saying that my class does not recognize -copyWithZone:. If I add that method, the exception
goes away and everything works fine. I've tried this on both the
latest GNUstep release and on trunk. Are the docs just out-of-date?

Yes, the documentation is just wrong. Dictionary keys do need to be copied.

I've fixed the documentation (at least, all the errors I spotted) in svn trunk to say that keys are copied.


possibly worthwile to explain why things are copied and not retained,
if you add a mutable object to a dictionary and subsequently modify the object in a way which modifies the objects -hash value, it would become inconsistent
with the hash value stored in the dictionary.



_______________________________________________
Gnustep-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to