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

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


  • Follow-Ups:
    • Re: copy versus arrayWithArray:
      • From: Greg Hurrell <email@hidden>
References: 
 >copy versus arrayWithArray: (From: Eric Scharff <email@hidden>)

  • Prev by Date: Receiving actions from WebViews
  • Next by Date: Re: copy versus arrayWithArray:
  • Previous by thread: Re: copy versus arrayWithArray:
  • Next by thread: Re: copy versus arrayWithArray:
  • Index(es):
    • Date
    • Thread