• 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: email@hidden
  • Date: Wed, 12 Jul 2006 10:19:41 +1000

What you return should be a copy--i.e. a completely new and different
instance. The caller should trust that any changes made to the copy are not
reflected in the original. You should *never* retain a current object and
return it. If you do this you aren't making a copy.

Not true; if your original object is immutable, you can just return [self retain]. copy is asking for an immutable "copy" of the receiver, where "copy" is really just "reference"; you typically shouldn't be using pointer equality or similar things for objects, so you really don't actually need multiple identical instances of an immutable instance. If your receiver is mutable you'd have to actually copy it in "copy", otherwise the instance could be modified later by some other code and confuse the receiver of the supposed copy.


Wade Tregaskis

    ICQ: 40056898
    AIM, Yahoo & Skype: wadetregaskis
    MSN: email@hidden
    iChat & email: email@hidden
    Jabber: email@hidden
    Google Talk: email@hidden

    http://homepage.mac.com/wadetregaskis/

-- Sed quis custodiet ipsos custodes?


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

  • Prev by Date: Re: Tables in TextView malformed after archiving and unarchiving
  • Next by Date: Re: Terminating from Separate Thread
  • Previous by thread: Re: copy vs mutableCopy?
  • Next by thread: Re: Re: copy vs mutableCopy?
  • Index(es):
    • Date
    • Thread