Created
April 16, 2012 05:48
-
-
Save ehuynh/2396566 to your computer and use it in GitHub Desktop.
iOS 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
static MyObject *singleton = nil; | |
+(MyObject *) sharedInstance { | |
NSLog (@"sharedInstance called."); | |
if (nil != singleton) return singleton; | |
static dispatch_once_t predicate; | |
dispatch_once(&predicate, ^{ | |
singleton = [[MyObject alloc] init]; | |
}); | |
return singleton; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment