• 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: Shawn Erickson <email@hidden>
  • Date: Fri, 18 Aug 2006 08:24:48 -0700


On Aug 18, 2006, at 7:24 AM, Greg Hurrell wrote:

El 18/08/2006, a las 15:32, Nir Soffer escribió:

On Aug 18, 2006, at 5:28 AM, Eric Scharff wrote:

NSArray *temp = [NSArray arrayWithArray: orig];

I would choose: [[orig copy] autorelease] because it is shorter and makes your intention more clear.

Except that the two statements aren't equivalent. A copy of a mutable array yields another mutable array (the poster said that "orig" is a mutable array).

No copy returns an immutable array (NSArray) in this case. For classes with the concept of immutable and mutable it is defined that copy returns an immutable version and mutableCopy returns a mutable version.


Review...

"The copy returned is immutable if the consideration “immutable vs. mutable” applies to the receiving object; otherwise the exact nature of the copy is determined by the class."

<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ Protocols/NSCopying_Protocol/Reference/Reference.html#//apple_ref/occ/ intfm/NSCopying/copyWithZone:>
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ Protocols/NSMutableCopying_Protocol/Reference/Reference.html#// apple_ref/occ/intfm/NSMutableCopying/mutableCopyWithZone:>


-Shawn _______________________________________________
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


References: 
 >copy versus arrayWithArray: (From: Eric Scharff <email@hidden>)
 >Re: copy versus arrayWithArray: (From: Nir Soffer <email@hidden>)
 >Re: copy versus arrayWithArray: (From: Greg Hurrell <email@hidden>)

  • Prev by Date: Re: copy versus arrayWithArray:
  • Next by Date: Re: Programmatically replace bound objects
  • Previous by thread: Re: copy versus arrayWithArray:
  • Next by thread: Re: copy versus arrayWithArray:
  • Index(es):
    • Date
    • Thread