工具类:快速创建单例
2016-04-05 16:12
489 查看
#import "CZTool.h" #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"%@",[CZTool shareTool]); NSLog(@"%@",[[CZTool alloc]init]); NSLog(@"%@",[[CZTool alloc]init]); } @end
#import <Foundation/Foundation.h> #import "CZSingle.h" @interface CZTool : NSObject CZSingleInterface(Tool) @end #import "CZTool.h" @implementation CZTool CZSingleImplementation(Tool) @end
创建头文件CZSingle.h // 两个##拼接字符串 把传过来的字符串拼接到##后面去 #define CZSingleInterface(name) +(instancetype)share##name; // 反斜杠用来宏定义换行拼接 #define CZSingleImplementation(name) + (instancetype)share##name {\ return [[self alloc]init];\ }\ + (instancetype)allocWithZone:(struct _NSZone *)zone {\ static dispatch_once_t onceToken;\ static id instance;\ dispatch_once(&onceToken, ^{\ instance = [super allocWithZone:zone];\ });\ return instance;\ }
相关文章推荐
- Wdatepicker日期控件的使用指南
- HDOJ 2614 Beat
- 关于EventBus用法总结
- 机器学习 Numpy Scipy Matplotlib Scikit-Learn的安装
- FragmentViewPager简单理解
- 【Chromium中文文档】Profile架构(看看谷歌家的重构)
- 浏览器环境下Javascript脚本加载与执行探析之DOMContentLoaded
- 【前端】使用CSS使元素居中的几种方式
- 本地Spring容器关闭的时机
- 快速gcd vs 普通gcd
- Redis命令-有序集合-zadd
- redis
- Peter and Snow Blower
- 宏和函数的区别
- spring框架学习(四)自动装配
- spring框架学习(三)junit单元测试
- vipca报错 CRS-1006,CRS-0215
- maven pom.xml各地址来源
- 【hihoCoder 1036】Trie图
- inline模式_大小写