Created
March 8, 2012 02:13
-
-
Save jarek-foksa/1998092 to your computer and use it in GitHub Desktop.
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* _instance = nil; | |
+(id)alloc { | |
@synchronized([MySingleton class]) { | |
NSAssert(_instance == nil, @"Error. Don't use alloc on singloetons."); | |
_instance = [super alloc]; | |
return _instance; | |
} | |
return nil; | |
} | |
+(MySingleton*)init { | |
@synchronized([MySingleton class]) { | |
if (!_instance) { | |
[[self alloc] _init]; | |
} | |
return _instance; | |
} | |
return nil; | |
} | |
-(id)_init { | |
NSLog(@"initing singleton"); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment