• 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
copy versus arrayWithArray:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: copy versus arrayWithArray:
      • From: Nir Soffer <email@hidden>
    • Re: copy versus arrayWithArray:
      • From: Chris Suter <email@hidden>
  • Prev by Date: NSPopUpButton inside Table CornerView
  • Next by Date: Re: copy versus arrayWithArray:
  • Previous by thread: Re: Re: NSPopUpButton inside Table CornerView
  • Next by thread: Re: copy versus arrayWithArray:
  • Index(es):
    • Date
    • Thread