Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Created June 28, 2014 07:57
Show Gist options
  • Save jhurliman/1f4c62298e77af4db32b to your computer and use it in GitHub Desktop.
Save jhurliman/1f4c62298e77af4db32b to your computer and use it in GitHub Desktop.
Singleton pattern in Objective-C
+ (instancetype)sharedInstance {
static id instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment