1.不再是常用的gcd模式。
https://www.cnblogs.com/selfing/p/4439234.html
2.防止在alloc
https://www.jianshu.com/p/4867dc92337e
3.对于allocWithZone的解读
https://blog.csdn.net/sbvfhp/article/details/47858469
4.最终写法
+ (instancetype)sharedManager;
static SGQRCodeScanManager *_instance;
+ (instancetype)sharedManager {
return [[self alloc] init];
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [super allocWithZone:zone];
});
return _instance;
}
`
网友评论