Created
October 2, 2012 02:13
-
-
Save jinthagerman/3815780 to your computer and use it in GitHub Desktop.
Singletons
This file contains hidden or 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 | |
+ (MySingleton*)singleton { | |
static MySingleton* __singleton = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
__singleton = [[MySingleton alloc] init]; | |
}); | |
return __singleton; | |
} | |
@end | |
OR | |
@implementation MySingleton | |
+ (id)singleton { | |
static MySingleton* __singleton = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
__singleton = [[MySingleton alloc] init]; | |
}); | |
return __singleton; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"@Class MySingleton;" I mean.