• 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: Greg Titus <email@hidden>
  • Date: Tue, 11 Jul 2006 08:50:54 -0700


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.

Hope this helps,
	- Greg
_______________________________________________
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 vs mutableCopy?
      • From: Rob Ross <email@hidden>
    • Re: copy vs mutableCopy?
      • From: "A.M." <email@hidden>
References: 
 >copy vs mutableCopy? (From: Rob Ross <email@hidden>)

  • Prev by Date: copy vs mutableCopy?
  • Next by Date: Re: copy vs mutableCopy?
  • Previous by thread: copy vs mutableCopy?
  • Next by thread: Re: copy vs mutableCopy?
  • Index(es):
    • Date
    • Thread