单例 宏代码 MRC 与 ARC
来源:互联网 发布:雅思自学 知乎 编辑:程序博客网 时间:2024/06/05 21:58
// ## : 连接字符串和参数
#define singleton_h(name) + (instancetype)shared##name;
#if __has_feature(obj_arc)//ARC
#define singleton_m(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:(struct _NSZone *)zone \
{ \
return _instance; \
}
#else//非ARC
#define singleton_m(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; \
} \
\
- (oneway void)release \
{ \
\
} \
\
- (id)autorelease \
{ \
return _instance; \
} \
\
- (id)retain \
{ \
return _instance; \
} \
\
- (NSUInteger)retainCount \
{ \
return 1; \
} \
\
+ (id)copyWithZone:(struct _NSZone *)zone \
{ \
return _instance; \
}
#endif
- 单例 宏代码 MRC 与 ARC
- 网络多线程 -单例模式业余练习代码MRC与ARC通用
- gcd单例mrc/arc
- 单例设计模式代码示例 MRC&ARC
- IOS GDC实现单例写法ARC与MRC
- iOS单例写成宏定义(ARC和MRC)
- 单例在ARC和MRC中
- ARC和MRC下的单例
- iOS单例设计 MRC&ARC
- iOS的ARC/MRC单例模式
- ARC与MRC转换
- ARC与MRC
- ARC与MRC混编
- OC ARC与MRC
- ARC 与 MRC 混编
- ARC 与 MRC 混编
- ARC与MRC
- 【iOS】ARC-MRC下的单例及其应用
- 从原字符串中得到一个字符串
- OC方法和文件编译(总结的很好拿来用了)
- js树形插件fancytree的使用
- 温故知新--Servlet(六)--HttpServletResponse对象
- 高精度大整数类
- 单例 宏代码 MRC 与 ARC
- 关于linux
- 日拱一卒(十七)
- UVA - 10714 - Ants
- BZOJ-3122-随机数生成器-SDOI2013-BSGS
- Maven去冲突jar示例(干货)
- Install MariaDB Server 10.0 on Ubuntu 14.04 LTS ( Trusty Tahr )
- 查看表空间
- Hadoop