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

Re: Ugly bug in Foundation, beware!


  • Subject: Re: Ugly bug in Foundation, beware!
  • From: Zach Wily <email@hidden>
  • Date: Thu, 3 Jun 2004 07:40:57 -0600

Nowhere in the documentation (that I can find) does it say that [NSMutableArray -copy] performs a deep copy. Why do you assume that it does?

(If it were to perform a deep copy, you'd only be able to add objects to NSMutableArrays that conformed to NSCopying, which I don't think any of us want.)

zach


On Jun 3, 2004, at 7:05 AM, 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 :(((((
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc

[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.
_______________________________________________
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: 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: Ugly bug in Foundation, beware!
  • Next by Date: Re: Debugging under 10.2
  • Previous by thread: Re: Ugly bug in Foundation, beware!
  • Next by thread: Re: Ugly bug in Foundation, beware!
  • Index(es):
    • Date
    • Thread