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

Re: behavior of -copy


  • Subject: Re: behavior of -copy
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 27 May 2010 09:29:55 -0700

On May 27, 2010, at 05:59, Ariel Feinerman wrote:

> my question is: what does -copy for immutable
> variant of immutable/mutable objects, for instance NSArray *arrayCopy =
> [array copy]; returns true copy or retains one?

The class of the variable 'arrayCopy' is irrelevant. If the instance being copied is a (subclass of) NSMutableArray, then it will use NSMutableArray's 'copy' implementation, which makes a "true" copy.

If the instance being copied is a (immutable subclass of) NSArray, then it will use NSArray's 'copy' implementation, which returns a retained reference to the original object.

Note that both of these behaviors are implementation details which are *not* guaranteed by the API.

> Or what does happen if
> object itself is immutable and has not setters, but it instance variables is
> mutable and can be changed?

There's no built-in behavior that applies to every class. It's up to each class to provide an implementation of 'copy:' (well, actually 'copyWithZone:') if it wants to conform to the NSCopying protocol. The current behavior of the Cocoa collection classes is as described above. The 'copy' behavior of other objects can only be described on a case-by-case basis.

You should take a look at the NSCopying Protocol Reference:

	http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Protocols/NSCopying_Protocol/Reference/Reference.html

for a more detailed answer to your question.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >behavior of -copy (From: Ariel Feinerman <email@hidden>)

  • Prev by Date: How to filter the NSOpenPanel with "Recommended Applications"
  • Next by Date: Re: How to filter the NSOpenPanel with "Recommended Applications"
  • Previous by thread: Re: behavior of -copy
  • Next by thread: How to filter the NSOpenPanel with "Recommended Applications"
  • Index(es):
    • Date
    • Thread