• 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
Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)


  • Subject: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 3 Jun 2004 14:49:42 +0100

On 3 Jun 2004, at 14:05, Ondra Cada wrote:

> Hi all,
>
> just bumped into this: mutable arrays do *NOT* deep copy upon receiving
> -copy
>
> #import <Foundation/Foundation.h>
> int main() {
> [NSAutoreleasePool new];
> id a=[NSMutableArray arrayWithObject:[NSMutableArray array]],b=[a
> copy];
> NSLog(@"contents: %x %x",[a lastObject],[b lastObject]);
> // this is why it is very very bad
> [[a lastObject] addObject:@"this is WAY wrong if seen in b!!!"];
> NSLog(@"changed a, my private b is %@",[b description]);
> return 0;
> }
>
> Didn't check mutable sets, dicts, et cetera, but i'd bet they share
> this howler :(((((

Are you certain that this is a bug? I don't see where in the
documentation for NSCopying it says that the copy is necessarily a deep
one, and it seems to make more sense in most cases for a collection
class's -copy to perform a shallow copy, especially for the very common
case where a collection is used to hold a set of immutable objects.

I actually think that it would be a bug if it performed a deep copy,
although it would be useful if there were a method that could be used
to perform deep copies for the few cases where that is what you really
want.

Kind regards,

Alastair.

--
http://www.alastairs-place.net

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
      • From: Julien Dufour <email@hidden>
    • Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
      • From: Ondra Cada <email@hidden>
References: 
 >Ugly bug in Foundation, beware! (From: Ondra Cada <email@hidden>)

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