#import "Tools.h"
//定义一个全局变量 static Tools *instances = nil;
@implementation Tools
- (id)copyWithZone:(NSZone *)zone{
return self; } +(id)allocWithZone:(struct _NSZone *)zone{
//线程保护 @synchronized(self){ if(instances == nil){
//如果第一次用,调用调服类方法 instances = [super allocWithZone:zone];
return instances; } } return instances; }
-(id)retain{ return self; }
-(NSUInteger)retainCount{ return NSUIntegerMax; }
-(oneway void)release{
}
-(id)autorelease{ return self; } //单例的接入点方法 +(instancetype)shareInstances{
//目的保证对象必须唯一 if(instances == nil){
//创建一个对象 instances = [[Tools alloc]init];
return instances; }
return instances; } @end
|