Skip to content

Instantly share code, notes, and snippets.

@0xlitf
Created December 5, 2015 10:48
Show Gist options
  • Save 0xlitf/365ab9e31fbd3349c56b to your computer and use it in GitHub Desktop.
Save 0xlitf/365ab9e31fbd3349c56b to your computer and use it in GitHub Desktop.
#define singleton
#define instance_interface(className, instanceMothed) \
\
+(instancetype)instanceMothed;
//实现方法
#define instance_implementation(className, instanceMothed) \
\
static className *_instance;\
\
+(instancetype)instanceMothed\
{ static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [[self alloc]init];\
});\
return _instance;\
}\
\
+(id)allocWithZone:(struct _NSZone *)zone{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}\
\
-(id)copyWithZone:(NSZone *)zone{\
return _instance;\
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment