把单例设成宏定义

#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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容