iOS 宏~单例封装宏
来源:互联网 发布:代码优化 编辑:程序博客网 时间:2024/06/15 23:19
//联系人:石虎 QQ: 1224614774 昵称:嗡嘛呢叭咪哄
1.SH前缀是作者名称简称"SH".2.宏定义直接拷贝到pch文件中即可.
1.使用方法.h
#import <Foundation/Foundation.h>
@interface MineAuthentication :NSObject
SHSingleInstance_H_(AuthenticationManager )
@end
2.使用方法.m
#import "SHMineAuthentication.h"
@interface MineAuthentication ()
@end
@implementation MineAuthentication
SHSingleInstance_M_(AuthenticationManager )
@end
二、单例实现和定义
//1.单例实现和定义宏--方便.h文件使用
#define SHSingleInstance_H_(name) \
+ (instancetype)shared##name;
//2.单例实现和定义宏--方便.m文件使用
#define SHSingleInstance_M_(name) \
static id _instance = nil; \
+ (instancetype)shared##name \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
if (_instance == nil) \
{ \
_instance = [[self alloc] init]; \
} \
}); \
return _instance; \
} \
\
+ (instancetype)allocWithZone:(struct _NSZone *)zone \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
if (_instance == nil) \
{ \
_instance = [super allocWithZone:zone]; \
} \
}); \
return _instance; \
} \
\
+ (id)copyWithZone:(struct _NSZone *)zone \
{ \
return _instance; \
} \
+ (id)mutableCopyWithZone:(struct _NSZone *)zone \
{ \
return _instance; \
}
三、单例调用
[MineAuthenticationsharedAuthenticationManager];
谢谢!!!
- iOS 宏~单例封装宏
- 浅谈——用宏封装单例
- sqlite单例封装
- AFNetworking封装单例
- okHttp单例封装
- iOS单例的宏定义
- iOS快速生成单例(宏)
- iOS 【单例模式 宏实现】
- 单例的一种封装
- OC单例 模板封装
- 单例 spdlog 封装类
- Okhttp3 简单单例封装
- 单例 封装PHP 数据库连接
- 书写一个完整的单例模式类,并封装为宏
- IOS开发中常用的单例模式宏定义
- iOS单例写成宏定义(ARC和MRC)
- iOS宏定义方法来初始化一个单例对象
- iOS通过宏定义来创建单例
- Es6知识点回顾
- Web安全
- 51nod 1742 开心的小Q(莫比乌斯函数)
- angularjs请求数据解析并渲染到表格中(天气预报)
- 使用markdown编辑器写博客
- iOS 宏~单例封装宏
- BOM ->History对象
- javascript的四种继承方式
- 练习题1
- opencv-python(10):图像平滑
- 原型链模式
- 深入理解java虚拟机-java内存区域
- VMware虚拟机 Ubuntu 16.04 安装 VMware Tools
- innerHTML和value属性的区别