Created
January 18, 2013 16:04
-
-
Save davidahouse/4565614 to your computer and use it in GitHub Desktop.
singleton using dispatch_once
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
+ (<class> *)shared<whatever> { | |
static <class> *shared<class> = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
shared<class> = [[self alloc] init]; | |
}); | |
return shared<class>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment