#import <Foundation/Foundation.h>
@interface Singleton : NSObject
+(Singleton *)shareInstance;
@end
#import "Singleton.h"
@implementation Singleton
+(Singleton *)shareInstance
{
static Singleton *singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singleton = [[super allocWithZone:NULL] init];
});
return singleton;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
return [Singleton shareInstance];
}
-(instancetype)copyWithZone:(struct _NSZone *)zone
{
return [Singleton shareInstance];
}
-(instancetype)mutableCopyWithZone:(struct _NSZone *)zone
{
return [Singleton shareInstance];
}
@end
最后編輯于 :
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者