标签:
HMDataTool.h #import <Foundation/Foundation.h> @interface HMDataTool : NSObject + (instancetype)sharedDataTool; @end HMDataTool.m #import "HMDataTool.h" @implementation HMDataTool // 用来保存唯一的单例对象 static id _instace; + (id)allocWithZone:(struct _NSZone *)zone { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instace = [super allocWithZone:zone]; }); return _instace; } + (instancetype)sharedDataTool { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instace = [[self alloc] init]; }); return _instace; } - (id)copyWithZone:(NSZone *)zone { return _instace; } @end
标签:
原文地址:http://www.cnblogs.com/521it/p/4980795.html