#import "Singleton.h"
@implementation Singleton
static Singleton* _instance = nil;
+(instancetype) shareInstance
{
static dispatch_once_t onceToken ; dispatch_once(&onceToken, ^{
_instance = [[super allocWithZone:NULL] init] ; }) ; return _instance ;
}
-(id) copyWithZone:(struct _NSZone *)zone
{
return [Singleton shareInstance] ;
}
@end
单例正确写法
最新推荐文章于 2021-03-09 16:14:24 发布