Re: safe and efficient way tp duplicate NSMutable array
Re: safe and efficient way tp duplicate NSMutable array
- Subject: Re: safe and efficient way tp duplicate NSMutable array
- From: "Jay" <email@hidden>
- Date: Tue, 17 Apr 2007 19:30:20 +0800
So, you are referring the "deep copying" to the copy that I can keep the
data contained in the original copy? (as the normal copy only do the
structral stuff but not the data and info within, that why it is called
"shallow")?
cheers,
Jay
----- Original Message -----
From: "Shawn Erickson" <email@hidden>
To: "Jay" <email@hidden>
Cc: <email@hidden>
Sent: Wednesday, April 18, 2007 7:11 AM
Subject: Re: safe and efficient way tp duplicate NSMutable array
On 4/17/07, Jay <email@hidden> wrote:
Hello,
I'm using NSMutabArray to store some instance objects of customer class,
I find it quite complex when try to create another identical MutableArray
object instance and it is easy to get into some troubles while
duplicating the array, will there be some safe ways to do it?
Thanks a lot. This may be some kind of simple questions but....
What is complex about [theMutableArray mutableCopy] or
[theMutableArray copy]? Also exactly what issues are you having
trouble with?
It is important to note that copies using the above are shallow
copies. In other words you get a new array instance referencing the
same set of object instance as the original array.
If you want a deep copy use [[NSMutableArray alloc]
initWithArray:sourceArray copyItems:YES] or [[NSArrray alloc]
initWithArray:sourceArray copyItems:YES] depending on what type of
array you want.
Obviously if you want a deep copy then all objects in the array have
to implement the NSCopying protocol so they can be copied fully.
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden