Last active
August 29, 2015 13:56
-
-
Save schystz/8860185 to your computer and use it in GitHub Desktop.
ObjC Singleton Class Template
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
@interface FooClass : NSObject | |
+ (FooClass *)sharedInstance; | |
@end |
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
@implementation FooClass | |
+ (FooClass *)sharedInstance | |
{ | |
static dispatch_once_t onceToken; | |
static FooClass *sharedInstance = nil; | |
dispatch_once(&onceToken, ^{ | |
sharedInstance = [[FooClass alloc] init]; | |
}); | |
return sharedInstance; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment