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: "Shawn Erickson" <email@hidden>
- Date: Tue, 17 Apr 2007 16:11:13 -0700
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