Re: copy vs mutableCopy?
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