Created
August 22, 2013 12:21
-
-
Save bragisig/6306483 to your computer and use it in GitHub Desktop.
Objective-C Singleton, creating shared instance
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
+ (MyClass *)sharedInstance | |
{ | |
// Static local predicate must be initialized to 0 | |
static MyClass *sharedInstance = nil; | |
static dispatch_once_t onceToken = 0; | |
dispatch_once(&onceToken, ^{ | |
sharedInstance = [[MyClass alloc] init]; | |
// Do any other initialisation stuff here | |
}); | |
return sharedInstance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment