Skip to content

Instantly share code, notes, and snippets.

@edwardinubuntu
Created January 9, 2011 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardinubuntu/771387 to your computer and use it in GitHub Desktop.
Save edwardinubuntu/771387 to your computer and use it in GitHub Desktop.
MySingleton.m
@implementation MySingleton
static MySingleton* _sharedInstance = nil;
+(MySingleton*)getInstance
{
@synchronized([MySingleton class])
{
if (!_sharedInstance)
[[self alloc] init];
return _sharedInstance;
}
return nil;
}
+(id)alloc
{
@synchronized([MySingleton class])
{
NSAssert(_sharedInstance == nil,
@"Attempted to allocate a second instance of a singleton.");
_sharedInstance = [super alloc];
return _sharedMySingleton;
}
return nil;
}
-(id)init {
self = [super init];
if (self != nil) {
// initialize stuff here
}
return self;
}
-(void)doSomething {
NSLog(@"Do the thing client want!");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment