#if 0
+ (SingleCase *)sharedSingleCase
{
// 上锁
@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
// 有一种单例的写法
+ (SingleCase *)sharedSingleCase
{
static dispatch_once_t oneToken;
dispatch_once(&oneToken, ^{
singleCase = [[super allocWithZone:NULL] init];
});
return singleCase;
}
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
- (id)mutableCopyWithZone:(NSZone *)zone
{
return self;
}
// 重写allocWithZone 防止别人alloc
+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
return [SingleCase sharedSingleCase];
}
// 防止copy 返回的还是同一个对象
+ (id)copyWithZone:(struct _NSZone *)zone
{
return [SingleCase sharedSingleCase];
}
+ (id)mutableCopyWithZone:(struct _NSZone *)zone
{
return [SingleCase sharedSingleCase];
}
- (oneway void)release
{
}
- (instancetype)autorelease
{
return self;
}
- (instancetype)retain
{
return self;
}
- (NSUInteger)retainCount
{
// 很大的一个数 release消息并没有什么卵用
return NSUIntegerMax;
}
// 全局静态变量 可以实现对象之间共享 静态存储区
static NSString * phoneNum = nil;