Created
December 5, 2015 10:49
-
-
Save 0xlitf/32fabe189831ee8d483d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //单例化一个类 instanceMothed:单例的方法名称 | |
| #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