Re: how to make an object with a single unique instance like NSNull?
Re: how to make an object with a single unique instance like NSNull?
- Subject: Re: how to make an object with a single unique instance like NSNull?
- From: "Mike R. Manzano" <email@hidden>
- Date: Tue, 29 Mar 2005 11:52:45 -0800
Here's some sample code that does this:
cIndexerThread* gIndexerThreadInstance = nil ;
@implementation cIndexerThread
+ (cIndexerThread*) instance
{
if( gIndexerThreadInstance == nil )
{
gIndexerThreadInstance = [ [ cIndexerThread alloc ] init ] ;
} // if gIndexerThreadInstance
return gIndexerThreadInstance ;
} // instance
@end
On Mar 29, 2005, at 10:39 AM, Matt Neuburg wrote:
On Tue, 29 Mar 2005 09:42:22 -0500, Johnny Deadman
<email@hidden>
said:
I need to make a version of NSNull for my own purposes (it has to be
a coredata* object so NSNull won't suffice) but I can't figure out
NSNull's trick of only having a single unique instance. In other words
[NSNull null]
always returns the same instance of NSNull no matter how many times
you call it.
How do I do this?
Implement singleton. If those words mean nothing to you, run, do not
walk,
to get "Design Patterns" (the book). While you're waiting for it to
arrive,
search on "singleton" in the archives and you'll see how to implement
it,
since this has been explained many times. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_______________________________________________
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
_______________________________________________
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