ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 低调看直播体育app软件下载 >> 移动开发 >> 单例抽取成宏

单例抽取成宏

来源:网络整理     时间:2016-06-04     关键词:宏

本篇文章主要介绍了"单例抽取成宏",主要涉及到宏方面的内容,对于移动开发感兴趣的同学可以参考一下: 代码可以下载链接,可以直接复制。#if __has_feature(objc_arc) //ARC//.h 拼接参数使用###define singleton_...

代码可以下载链接,可以直接复制。

#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

以上就介绍了单例抽取成宏,包括了宏方面的内容,希望对移动开发有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_1490883.html

相关图片

相关文章