import <Foundation/Foundation.h>
@interface MFShareTool : NSObject<NSCopying,NSMutableCopying>
+(instancetype)shareTool;
@end
import "MFShareTool.h"
@implementation MFShareTool
static MFShareTool * _shareTool;
+(instancetype)allocWithZone:(struct _NSZone *)zone{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_shareTool = [super allocWithZone:zone];
});
return _shareTool;
}
+(instancetype)shareTool{
return [[self alloc]init];
}
-(id)copyWithZone:(NSZone *)zone{
return _shareTool;
}
-(id)mutableCopyWithZone:(NSZone *)zone{
return _shareTool;
}
// 判断环境是否为ARC
if __has_feature(objc_arc)
else
-(oneway void)release {
}
-(instancetype)retain{
return _shareTool;
}
-(NSUInteger)retainCount{
return MAXFLOAT;
}
endif
@end
!!! 注意点
单例不能使用继承
网友评论