• 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: Andreas Mayer <email@hidden>
  • Date: Tue, 11 Jul 2006 18:44:41 +0200


Am 11.07.2006 um 18:07 Uhr schrieb Rob Ross:

As a followup, say I have an object with one instance variable, an NSMutableString. And say some code calls -copy on this object. You're saying that the intent is for an immutable copy? So I just retain the ivar and copy the reference to a new object and return that instance, even though the ivar is itself mutable? As the implementor of the -copy method, I am trusting that the client will not make changes to this value since it would affect another instance? Is this correct?

And similarly, if -mutableCopy is called, I would make a deep copy of the NSMutableString, even though it's already mutable, because the intent of the caller is to modify that value and I don't want the original object mutated? Is this also correct?

That really depends on the type of object.

It is my understanding, that mutableCopy is mostly used in conjunction with collections.

Considering "normal" objects, the user will not modify any ivars directly anyway, so there is no case for mutable/immutable copy here. If you want the user to be able to modify a property on your object, you will offer accessor methods to change the corresponding instance variable. That will work, no matter if the previous value was retained or copied.


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

  • Prev by Date: Re: non-ASCII characters in CFString literal [Was: (no subject)]
  • Next by Date: Re: Norwegian characters in some Objective-C code (was No subject)
  • Previous by thread: Re: copy vs mutableCopy?
  • Next by thread: Re: copy vs mutableCopy?
  • Index(es):
    • Date
    • Thread