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: Shaun Wexler <email@hidden>
- Date: Thu, 1 Dec 2005 21:28:40 -0800
On Dec 1, 2005, at 9:22 PM, Jeff Laing wrote:
Shaun and Malcolm have already pointed out two scenarios where
copying of a
singleton might happen, even though the copier didn't want a
"writable" copy
or even an "functionally independent" one. But because they were the
general case (dictionary keys, accessors), they were *required* to
take the
copy
In both cases, I think, the probability of the scenarios actually
happening
(one of my accessors returning the [NSDocumentController
sharedInstance], or
using it as a key in a dictionary) are pretty small. But I concede
that
they are not completely irrational, so it does make sense for your
singleton
to munge copyWithZone:
I neglected to mention the main reason for overriding methods such as
-copy. Often you need to prevent the superclass methods from being
called, this being the prime example. NSObject implements -copy
using NSCopyObject(), which would physically duplicate the singleton
in memory, and return what would appear to be an already-initialized
and fully functional copy. Nah so good, eh? ;)
--
Shaun Wexler
MacFOH
http://www.macfoh.com
"No problem is so formidable that you can't walk away from it." -
Charles Schulz
_______________________________________________
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