-
(instancetype)SharedDataHandle {
return [[self alloc] init];
}
-
(instancetype)allocWithZone:(struct _NSZone *)zone {
static dispatch_once_t onceToken;
static JYDataHandle* _once = nil;
dispatch_once(&onceToken, ^{
_once = [[super allocWithZone:NULL]init];
});return _once;
}
两种方法得到的都是同一个对象
JYDataHandle *once1 = [JYDataHandle once];
NSLog(@"%@", once1);
JYDataHandle*once2 = [[JYDataHandle alloc]init];
NSLog(@"%@", once2);
网友评论