Skip to content

Instantly share code, notes, and snippets.

@andrei512
Created August 22, 2013 11:22
Show Gist options
  • Save andrei512/6306023 to your computer and use it in GitHub Desktop.
Save andrei512/6306023 to your computer and use it in GitHub Desktop.
The true Objective-C singleton
+ (id)alloc {
static dispatch_once_t onceToken;
static SettingsViewController *singleton = nil;
dispatch_once(&onceToken, ^{
singleton = [super alloc];
});
return singleton;
}
- (id)init {
static dispatch_once_t onceToken;
static SettingsViewController *singleton = nil;
dispatch_once(&onceToken, ^{
singleton = [super init];
});
return singleton;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment