Last active
September 7, 2017 09:16
-
-
Save Huang-Libo/4d4e6080ec467faf05ebe1b02b34704c to your computer and use it in GitHub Desktop.
Objective-C singleton
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
// `dispatch_once' singleton initialisation | |
+ (id)sharedInstance { | |
static EOCClass *sharedInstance = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
sharedInstance = [[self alloc] init]; | |
}); | |
return sharedInstance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment