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: Gregory Weston <email@hidden>
- Date: Tue, 29 Mar 2005 13:01:41 -0500
On Mar 29, 2005, at 9:46 AM, Johnny Deadman wrote:
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?
For exhaustive discussion, poke around in whatever literature you like
for the concept called a singleton. But the general form is that you
keep, private to the class, an instance that you'll return when asked
for it. You could create it either in the initialize class method or
defer creation to the first time it's actually requested. Given an
Objective-C implementation, you'd probably also want to write init so
that if someone tried to create one directly you can release the object
they allocated and give back your shared object.
G
_______________________________________________
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