• 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: help needed with OO concepts when copying
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: help needed with OO concepts when copying


  • Subject: RE: help needed with OO concepts when copying
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Tue, 11 Feb 2003 16:30:21 -0500

An NSArray contains pointers, not values. When you copy an NSArray (or
NSMutableArray), you copy the pointers. If the pointers are to mutable
objects, and those objects change, the "contents" of both arrays change.

What you want to do is make a "deep copy" of the array by enumerating
through it and doing mutableCopy on each of its objects, then adding those
copies to a new array.

With immutable objects in an array, this is not any issue. A regular copy
does what you need. Indeed, a retain will usually do the trick.

Jonathan

> -----Original Message-----
> From: email@hidden
> [mailto:email@hidden]On Behalf Of Denis Stanton
> Sent: Tuesday, February 11, 2003 2:56 PM
> To: email@hidden
> Subject: help needed with OO concepts when copying
>
>
> Hi
>
> I hope someone can help me out with a gap in my understanding of object
> concepts. I'm trying to make a copy of an MSMutableArray, so that I
> have two arrays. I then try and modify the text contents of one of the
> arrays and I see the same changes occur in the other array. This tells
> me that rather than making two arrays all I am doing is making two
> references to the same one. I have spent many hours trying to figure
> out this copying thing, but I'm stumped. How do I make a separate copy
> of an array with the same initial values as the original, but otherwise
> independent of it? [snip]
_______________________________________________
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: help needed with OO concepts when copying
      • From: Denis Stanton <email@hidden>
References: 
 >help needed with OO concepts when copying (From: Denis Stanton <email@hidden>)

  • Prev by Date: Re: how is C often used in Cocoa, if at all?
  • Next by Date: Re: How do I change the enddate for a runloop?
  • Previous by thread: help needed with OO concepts when copying
  • Next by thread: Re: help needed with OO concepts when copying
  • Index(es):
    • Date
    • Thread