item gcd singleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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