Re: Ugly bug in Foundation, beware!
Re: Ugly bug in Foundation, beware!
- Subject: Re: Ugly bug in Foundation, beware!
- From: Nicko van Someren <email@hidden>
- Date: Thu, 3 Jun 2004 14:52:30 +0100
On 3 Jun 2004, at 14:05, Ondra Cada wrote:
just bumped into this: mutable arrays do *NOT* deep copy upon receiving
-copy
...
Didn't check mutable sets, dicts, et cetera, but i'd bet they share
this howler :(((((
What makes you think that this is a bug and not a design feature? The
array class knows nothing of the objects it holds, it simply holds a
set of pointers. The copy of the array contains copies of those
pointers. The implementation of -copy and -copyWithZone: are
explicitly stated as being up to the class.
If you need a copy of an array with copies of the objects that it holds
you can use
NSArray *a, *b;
...
b = [[NSArray alloc] initWithArray: a copyItems: YES];
Of course this is still not a true deep copy since all it does to copy
the items is send them a -copyWithZone: message.
Nicko
_______________________________________________
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.