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: Hamish Allan <email@hidden>
- Date: Sat, 26 Nov 2005 19:21:25 +0000
Have I missed some important detail in this debate? It is starting to
feel like I must have! Or is everyone missing the wood for the trees?
The [[NSFoo] sharedFoo] technique works for most situations that
require the singleton pattern, and is very simple to implement. It
does not guarantee that the shared instance will never be released,
but then again if you don't follow the rules about alloc/copy/retain/
release you're on your own anyway. If you need to use your singleton
as a key in a dictionary or something which would copy it, just do
what you would do if you were writing an immutable class and retain
it instead. If you're concerned that people using your class will do
things they shouldn't, just write helpful "warn if instance already
allocated" wrappers around e.g., allocWithZone:.
Best wishes,
Hamish
_______________________________________________
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