码迷,mamicode.com
首页 > 移动开发 > 详细

iOS单例宏

时间:2016-08-11 13:11:15      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

//
//  Single.h
//  FKLTest
//
//  Created by kun on 16/8/11.
//  Copyright © 2016年 kun. All rights reserved.
//

#ifndef Single_h
#define Single_h

#define SingelH(name) +(instancetype)share##name;

#if __has_feature(objc_arc) // 条件编译 ARC
#define SingelM(name) static id share##name = nil;+ (instancetype)allocWithZone:(struct _NSZone *)zone{static dispatch_once_t onceToken;dispatch_once(&onceToken, ^{if ( !share##name ){share##name = [super allocWithZone:zone];}});return share##name;}+ (instancetype)share##name{return [[self alloc] init];}- (id)copyWithZone:(NSZone *)zone{return share##name;}- (id)mutableCopyWithZone:(NSZone *)zone{return share##name;}
#else // 条件编译 MRC
#define SingelM(name) static id share##name = nil;+ (instancetype)allocWithZone:(struct _NSZone *)zone{static dispatch_once_t onceToken;dispatch_once(&onceToken, ^{if ( !share##name ){share##name = [super allocWithZone:zone];}});return share##name;}+ (instancetype)share##name{return [[self alloc] init];}- (id)copyWithZone:(NSZone *)zone{return share##name;}- (id)mutableCopyWithZone:(NSZone *)zone{return share##name;}- (oneway void)release{}- (instancetype)retain{    return shared##name;}- (NSUInteger)retainCount{    return MAXFLOAT;}
#endif // 条件编译

#endif /* Single_h */

 

iOS单例宏

标签:

原文地址:http://www.cnblogs.com/fkunlam/p/5760485.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!