Re: Is Apple's singleton sample code correct?
Re: Is Apple's singleton sample code correct?
- Subject: Re: Is Apple's singleton sample code correct?
- From: Charilaos Skiadas <email@hidden>
- Date: Thu, 1 Dec 2005 23:12:30 -0600
On Dec 1, 2005, at 10:41 PM, Jeff Laing wrote:
This is no different than making a "copy" of an immutable
object such as a NSData or NSString... most classes will simply
retain the
object, which isn't allowed to change or move.
Agreed. I wouldn't copy those either. Why would you?
Please remember, I'm asking this from the novices perspective? I
seriously
don't know why I would call [NSString copy] since NSString is
supposed to be
immutable.
Alright, I do know that it might really be an NSMutableString under
the
covers so its a poor example.
Actually this is a very good example. In this case, you want to work
with this string and make sure that nothing you don't have control
over will change it, and so you want to copy it. You shouldn't be
concerned whether it's actually an NSString, or an NSMutableString
disguised as a string.
I think this is very different than the singleton case though. The
same document (NSCopying Protocol) says:
The exact meaning of “copy” can vary from class to class, but a copy
must be a functionally independent object with values identical to
the original at the time the copy was made"
By "functionally independent" I take it to mean that if you change
any of the values of the object and its variables, then this only
changes the object that you have as a copy. You don't expect that
change to carry over to the original object. In the case of the
immutable classes, that's a moot point, but in the case of a
singleton, the object variables of the copy are the same as the
object variables of the original, which I think breaks the contract
of the NSCopying protocol. Please correct me if I am wrong here.
Haris
_______________________________________________
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