工具类:快速创建单例
来源:互联网 发布:psp游戏数据已损坏 编辑:程序博客网 时间:2024/06/06 03:58
#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 : NSObjectCZSingleInterface(Tool)@end#import "CZTool.h"@implementation CZToolCZSingleImplementation(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;\}
0 0
- 工具类:快速创建单例
- 快速实现单例的工具类
- iOS快速创建单例
- 快速创建一个单例singleton
- MFC单文档之快速创建多个对话框类
- java学习笔记:面向对象编程之工具类的创建与单例设计模式
- 单例吐司工具类
- 单例模式(创建类)
- jdbc工具类(单例模式)
- 单例模式建立工具类
- JAVA单例MongoDB工具类
- JAVA单例MongoDB工具类
- java工具类2---单例模式
- Retrofit单例封装工具类
- jackson 单例工具
- 用static 创建类的单例
- 创建类模式之一单例模式
- dispatch_once创建单例
- 增加 cookie 安全性添加HttpOnly和secure属性
- fragment 重影问题,原来是布局id相同导致的
- Android根据文件名(String类型)去查找R文件中的对应id(int类型)
- ViewPager 简单分析
- CSS学习笔记(二)选择器
- 工具类:快速创建单例
- ubuntu 14.4常见命令
- hdoj 1426 Sudoku Killer
- FragmentViewPager简单理解
- 机器学习 Numpy Scipy Matplotlib Scikit-Learn的安装
- Leetcode 90. Subsets II
- 友盟第三方登陆,及分享,使用工具集成。
- 对英文单词按照字母顺序进行排序(升序or降序)
- MVC中的ActionResult的子类介绍