Skip to content

Instantly share code, notes, and snippets.

@arkilis
Created May 17, 2017 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkilis/c3a51a4ef976ebda5c09cdfa33c5d6bd to your computer and use it in GitHub Desktop.
Save arkilis/c3a51a4ef976ebda5c09cdfa33c5d6bd to your computer and use it in GitHub Desktop.
item gcd singleton
#import "Item.h"
static id _instance;
@implementation Item
+ (id)allocWithZone:(struct _NSZone *)zone
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [super allocWithZone:zone];
});
return _instance;
}
+ (instancetype)sharedInstance
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[self alloc] init];
});
return _instance;
}
- (id)copyWithZone:(NSZone *)zone
{
return _instance;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment