iOS 宏~单例封装宏

//联系人:石虎  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];



谢谢!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值