@implementationfirstVc
//管方說這是由于歷史原因還存在.參數(shù)管方建義傳入null
+(instancetype)allocWithZone:(struct_NSZone*)zone{
return[superallocWithZone:zone];
}
+(instancetype)firstVC{
staticfirstVc* vc;
staticdispatch_once_toneToken;
dispatch_once(&oneToken, ^{
//vc = [[superalloc]init];
vc = [[firstVcallocWithZone:nil]init];
});
returnvc;
}
//重寫alloc
+(instancetype)alloc{
return[firstVcfirstVC];
}
-(instancetype)init{
self= [superinit];
returnself;
}
//第二種寫法
@implementationfirstVc
staticfirstVc*shareVc;
//管方說這是由于歷史原因還存在.參數(shù)管方建義傳入null
+(instancetype)allocWithZone:(struct_NSZone*)zone{
return[superallocWithZone:zone];
}
+(instancetype)firstVC{
//
//static firstVc * vc;
//static dispatch_once_t oneToken;
//
//dispatch_once(&oneToken, ^{
//vc = [[super alloc] init];
//});
//return vc;
if(!shareVc) {
shareVc= [[superalloc]init];
}
returnshareVc;
}
//重寫alloc
+(instancetype)alloc{
return[firstVcfirstVC];
}
-(instancetype)init{
self= [superinit];
returnself;
}