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

iOS-简化单例模式(定义成宏 以后通用)

时间:2015-10-03 15:38:37      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

// .h文件
#define HMSingletonH + (instancetype)sharedInstance;

// .m文件
#define HMSingletonM static id _instance;  + (id)allocWithZone:(struct _NSZone *)zone {     static dispatch_once_t onceToken;     dispatch_once(&onceToken, ^{         _instance = [super allocWithZone:zone];     });     return _instance; }  + (instancetype)sharedInstance {     static dispatch_once_t onceToken;     dispatch_once(&onceToken, ^{         _instance = [[self alloc] init];     });     return _instance; }  - (id)copyWithZone:(NSZone *)zone {     return _instance; }

 

iOS-简化单例模式(定义成宏 以后通用)

标签:

原文地址:http://www.cnblogs.com/zhuyaguang/p/4853400.html

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