Created
January 9, 2011 03:27
-
-
Save edwardinubuntu/771387 to your computer and use it in GitHub Desktop.
MySingleton.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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