码迷,mamicode.com
首页 > Web开发 > 详细

非ARC MVC 单例使用宏

时间:2015-08-07 12:59:06      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

// .h文件
#define HMSingletonH(name) + (instancetype)shared##name; // .m文件
#define HMSingletonM(name) static id _instance; + (id)allocWithZone:(struct _NSZone *)zone { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instance = [super allocWithZone:zone]; }); return _instance; } + (instancetype)shared##name { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instance = [[self alloc] init]; }); return _instance; } - (id)copyWithZone:(NSZone *)zone { return _instance; } - (oneway void)release { } - (id)retain { return self; } - (NSUInteger)retainCount { return 1;} - (id)autorelease { return self;}

 

非ARC MVC 单例使用宏

标签:

原文地址:http://www.cnblogs.com/lizhan1991/p/4710260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!