#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
网友评论