// // 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 */