copy versus arrayWithArray:
copy versus arrayWithArray:
- Subject: copy versus arrayWithArray:
- From: Eric Scharff <email@hidden>
- Date: Thu, 17 Aug 2006 19:28:32 -0700 (PDT)
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.
However, which version is better/faster, especially if I have a
fairly large array?
Thanks,
-Eric
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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