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

把单例设成宏定义

作者: 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

    相关文章

      网友评论

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

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