• 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 vs mutableCopy?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: copy vs mutableCopy?


  • Subject: Re: copy vs mutableCopy?
  • From: "A.M." <email@hidden>
  • Date: Tue, 11 Jul 2006 11:56:59 -0400 (EDT)

On Tue, July 11, 2006 11:50 am, Greg Titus wrote:
> On Jul 11, 2006, at 8:50 AM, Rob Ross wrote:
>
>> Ok, I know the difference between a mutable and immutable object.
>> And I know the difference between a shallow copy and a deep copy.
>>
>>
>> But I am having trouble understanding the difference between
>> implementing copy vs mutable copy, since it seems you can make mutable
>> copies of immutable objects, and immutable copies of mutable objects.
>> I'm just a bit confused how this works in practice.
>>
>>
>> I've read this:
>>
>>
>> http://developer.apple.com/documentation/Cocoa/Conceptual/
>> MemoryMgmt/Tasks/ImplementCopy.html
>>
>>
>> but it doesn't really tell me the difference between the two methods.
>
> The difference is in the intent of the caller. You make a mutableCopy
> when you want to make a copy that you can later modify for yourself, and
> make a copy when you want to make a copy to hold onto unchanged.
>
> For many objects, the implementation of the two methods can be
> identical. But knowing the intent of the caller allows certain
> optimizations, such as returning the same immutable object (just retained
> again) from a call to -copy, because you know that the caller just wants
> something to hold onto unchanged, and the existing object can not change.

Also, mutable classes are sometimes subclasses of their immutable
brethren, so a -copy might fall through to the superclass. A lot of
classes are inherently mutable, so copy will return the mutable copy
anyway. Note that the NSCopying protocol only requires -copyWithZone: so
it has no notion of mutability.

-M


 _______________________________________________
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 vs mutableCopy? (From: Rob Ross <email@hidden>)
 >Re: copy vs mutableCopy? (From: Greg Titus <email@hidden>)

  • Prev by Date: Re: copy vs mutableCopy?
  • Next by Date: Re: adding audio to a movie file
  • Previous by thread: Re: copy vs mutableCopy?
  • Next by thread: Re: copy vs mutableCopy?
  • Index(es):
    • Date
    • Thread