Re: copy versus arrayWithArray:
Re: copy versus arrayWithArray:
- Subject: Re: copy versus arrayWithArray:
- From: Nir Soffer <email@hidden>
- Date: Fri, 18 Aug 2006 16:32:27 +0300
On Aug 18, 2006, at 5:28 AM, Eric Scharff wrote:
I need to make a shallow copy of an array because I need to
iterate over the contents of a mutable array, and during that
iteration I will need to change the original array:
NSArray *temp = [NSArray arrayWithArray: orig];
NSEnumermerator *items = [temp objectEnumerator];
id item;
while ((item = [items nextObject]) {
// Possibly call [orig addObject: ] or removeObject:
}
Both NSMutableArray -copy and NSArray +arrayWithArray: methods
ought to solve the task for me. I lean toward the
+arrayWithArray: version because that way my temporary copy is
automatically autoreleased, which is precisely what I want.
I would choose: [[orig copy] autorelease] because it is shorter and
makes your intention more clear.
Best Regards,
Nir Soffer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden