代码能够下载,连接在最下面,也能够直接复制下面的代码,本身新建一个类。spa
用法及其简单。例如it
.h文件io
#import <Foundation/Foundation.h>import
//引入头文件下载
#import "singleton.h"im
@interface DBTools : NSObjectstatic
//.h的宏di
singleton_h(DBTools)文件
@endcopy
.m文件
#import "DBTools.h"
@implementation DBTools
//.m的宏
singleton_m(DBTools)
@end
//============这是抽取的内容=================
#if __has_feature(objc_arc) //ARC
//.h 拼接参数使用##
#define singleton_h(name) +(instancetype)sharad##name;
//.m 宏里面换行
#define singleton_m(name) static id _instanceType;\
+(instancetype)sharad##name\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instanceType = [[self alloc]init];\
});\
return _instanceType;\
}\
+ (instancetype)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instanceType = [super allocWithZone:zone];\
});\
return _instanceType;\
}\
-(id)copyWithZone:(NSZone *)zone\
{\
return _instanceType;\
}
#else //MRC
//.h 拼接参数使用##
#define singleton_h(name) +(instancetype)sharad##name;
//.m 宏里面换行
#define singleton_m(name) static id _instanceType;\
+(instancetype)sharad##name\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instanceType = [[self alloc]init];\
});\
return _instanceType;\
}\
+ (instancetype)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instanceType = [super allocWithZone:zone];\
});\
return _instanceType;\
}\
-(id)copyWithZone:(NSZone *)zone\
{\
return _instanceType;\
}\
-(oneway void)release\
{\
\
}\
-(instancetype)retain\
{\
return _instanceType;\
}\
-(instancetype)autorelease\
{\
return _instanceType;\
}\
- (NSUInteger)retainCount\
{\
return 1;\
}
#endif
下载连接地址⬇️
http://pan.baidu.com/s/1mhKHg7Y