Skip to content

Instantly share code, notes, and snippets.

@dutran90
Created August 18, 2015 16:05
Show Gist options
  • Save dutran90/0701d048c1af3326d447 to your computer and use it in GitHub Desktop.
Save dutran90/0701d048c1af3326d447 to your computer and use it in GitHub Desktop.
Design Pattern
// SINGLETON PATTERN
-->.h:
+ (instancetype)sharedInstance;
-->.m:
+ (instancetype)sharedInstance
{
static MyClass *sharedInstance = nil;
static dispatch_once_t onceToken;
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