美文网首页
把单例设成宏定义

把单例设成宏定义

作者: Kloar | 来源:发表于2016-03-11 13:02 被阅读51次

#undef  AS_SINGLETON#define AS_SINGLETON( __class ) \- (__class *)sharedInstance; \+ (__class *)sharedInstance;#undef  DEF_SINGLETON#define DEF_SINGLETON( __class ) \- (__class *)sharedInstance \{ \    return [__class sharedInstance]; \} \+ (__class *)sharedInstance \{ \    static dispatch_once_t once; \    static __class * __singleton__; \    dispatch_once( &once, ^{ __singleton__ = [[[self class] alloc] init]; } ); \    return __singleton__; \}#undef  DEF_SINGLETON_AUTOLOAD#define DEF_SINGLETON_AUTOLOAD( __class ) \- (__class *)sharedInstance \{ \    return [__class sharedInstance]; \} \+ (__class *)sharedInstance \{ \    static dispatch_once_t once; \    static __class * __singleton__; \    dispatch_once( &once, ^{ __singleton__ = [[[self class] alloc] init]; } ); \    return __singleton__; \} \+ (void)load \{ \    [self sharedInstance]; \}#import@interface Danli_yinhangkaMsg : NSObject

.h

.m

#import "Danli_yinhangkaMsg.h"

@implementation Danli_yinhangkaMsg

DEF_SINGLETON(Danli_yinhangkaMsg)

-(NSMutableArray *)data_array_YHK

{

//判断是否已经有了,若没有,则进行实例化

if (!_data_array_YHK) {

_data_array_YHK=[[NSMutableArray alloc]init];

}

return _data_array_YHK;

}

@end


http://blog.csdn.net/chaoyuan899/article/details/17524575

相关文章

  • 把单例设成宏定义

    #undef AS_SINGLETON#define AS_SINGLETON( __class ) \- (__...

  • 0922 宏定义通杀单例

    1、单例宏定义源码 说明此宏定义精华就是把声明文件和执行文件都放在宏定义了,而且针对不同的类,生成不同的单例,使用...

  • iOS 单例

    单例模式实现不能使用继承 定义单例实现 简写 定义单例实现宏

  • iOS 单例宏定义记录

    MYSingleton.h : 单例宏定义 - 头文件

  • 单例的宏定义

    用宏定义把单例忘了吧。。 #ifndef Singleton_h#define Singleton_h#defin...

  • 宏定义单例

    新建.h文件## 在.h文件中代码如下: 使用方法: 新建类FirstFirst.h中 First.m中 Firs...

  • 单例

    单例 单例宏

  • 宏定义单例类

  • 单例的宏定义

    序言 单例的使用在我们开发iOS程序的时候的使用率是非常高的,在我们写一个单例的时候,可能不止会用到一个单例,然而...

  • 单例的宏定义

    #define DEFINE_SINGLETON_FOR_HEADER(className) \ \ + (cla...

网友评论

      本文标题:把单例设成宏定义

      本文链接:https://www.haomeiwen.com/subject/ugtxlttx.html