Jump to content

Singleton: Difference between revisions

no edit summary
(Created Global Singleton class)
 
No edit summary
Line 40:
// And any other protected methods.
}
</pre>
 
 
=={{header|Objective-C}}==
(Using Cocoa's NSObject as a base class)
<pre>
// SomeSingleton.h
@interface SomeSingleton : NSObject
{
// any instance variables
}
 
+ (SomeSingleton*)sharedInstance;
 
@end
</pre>
 
<pre>
// SomeSingleton.m
@implementation SomeSingleton
 
+ (GameController*) sharedInstance
{
static sharedInstance = nil;
if(!sharedInstance) {
sharedInstance = [[SomeSingleton alloc] init];
}
return sharedInstance;
}
 
@end
</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.