单例
来源:互联网 发布:电信机顶盒装软件 编辑:程序博客网 时间:2024/04/30 01:55
// @interface
#define singleton_interface(className) \
+ (className *)shared##className;
// @implementation
#define singleton_implementation(className) \
static className *_instance; \
+ (id)allocWithZone:(NSZone *)zone \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
return _instance; \
} \
+ (className *)shared##className \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[self alloc] init]; \
}); \
return _instance; \
}
#define singleton_interface(className) \
+ (className *)shared##className;
// @implementation
#define singleton_implementation(className) \
static className *_instance; \
+ (id)allocWithZone:(NSZone *)zone \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
return _instance; \
} \
+ (className *)shared##className \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[self alloc] init]; \
}); \
return _instance; \
}
0 0
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- 单例
- JAVA-JSP/Servlet 笔记(九)
- web图片或者上传
- 分类器的评价
- 5-24 约分最简分式
- 模拟 Codeforces620F Xors on Segments
- 单例
- tomcat 修改端口为80
- matlab画图,变长坐标轴
- MySQL多表连接删除问题相关
- 【HDU】 2795 Billboard
- AdSupport(简介)
- C++面试题(一)
- GitHub超详细图文攻略 - Git客户端下载安装 GitHub提交修改源码工作流程 Git分支 标签 过滤 Git版本工作流
- IOS后台常驻,实现后台下载