版权声明:本文为博主原创文章,未经博主允许不得转载。 https://cloud.tencent.com/developer/article/1338220
#if 0
{
// 上锁
@synchronized(self){
if (singleCase == nil) {
// 几种单例写法
// singleCase = [SingleCase alloc init];
// singleCase = [SingleCase allocWithZone:<#(struct _NSZone *)#>;
// singleCase = [self alloc init];
// singleCase = [self allocWithZone:NULL init];
singleCase = [super allocWithZone:NULL init];
}
}
return singleCase;
}
#endif
// 有一种单例的写法
{
static dispatch_once_t oneToken;
dispatch_once(&oneToken, ^{
singleCase = [super allocWithZone:NULL init];
});
return singleCase;
}
{
return self;
}
{
return self;
}
// 重写allocWithZone 防止别人alloc
{
return SingleCase sharedSingleCase;
}
// 防止copy 返回的还是同一个对象
{
return SingleCase sharedSingleCase;
}
{
return SingleCase sharedSingleCase;
}
{
}
{
return self;
}
{
return self;
}
{
// 很大的一个数 release消息并没有什么卵用
return NSUIntegerMax;
}
// 全局静态变量 可以实现对象之间共享 静态存储区
static NSString * phoneNum = nil;