Created
December 5, 2015 10:48
-
-
Save 0xlitf/365ab9e31fbd3349c56b to your computer and use it in GitHub Desktop.
#define singleton
This file contains 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
#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