Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DanielKoehler/8720193 to your computer and use it in GitHub Desktop.

Select an option

Save DanielKoehler/8720193 to your computer and use it in GitHub Desktop.
+ (instancetype)singleton {
static id singletonInstance = nil;
if (!singletonInstance) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singletonInstance = [[super allocWithZone:NULL] init];
});
}
return singletonInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
return [self singleton];
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment