Created
August 22, 2013 11:22
-
-
Save andrei512/6306023 to your computer and use it in GitHub Desktop.
The true Objective-C singleton
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
+ (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