Skip to content

Instantly share code, notes, and snippets.

@Kevinwlee
Created May 2, 2012 14:35
Show Gist options
  • Save Kevinwlee/2576996 to your computer and use it in GitHub Desktop.
Save Kevinwlee/2576996 to your computer and use it in GitHub Desktop.
Love this Pattern for generating a single instance of an object
@implementation QTSomeClient
+ (QTSomeClient *)sharedClient {
static QTSomeClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [QTSomeClient new];
});
return _sharedClient;
}
- (id)init {
self = [super init];
if (!self) {
return nil;
}
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment