taiyang2014

单例初始化宏定义

1.创建.h文件...
2.
#define DEFINE_SINGLETON_FOR_HEADER(className) \
\
+ (className *)shared##className;


#define DEFINE_SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}

posted on 2015-12-04 16:59  taiyang2014  阅读(174)  评论(0编辑  收藏  举报

导航