static MyVC *_sharedInstance = nil;//可以是vc,也可以是obj
@implementation MyVC
//第一种
+ (instancetype)sharedInstance
{
static dispatch_once_t once;//加锁
dispatch_once(&once, ^{
_sharedInstance = [[MyVC alloc] init];
[_sharedInstance view];
});
return _sharedInstance;
}
//第二种 不建议使用
+(instancetype)sharedMyReuqest
{
@synchronized (self){
if (!_sharedInstance) {
_sharedInstance= [[MyVC alloc]init];
}
return _sharedInstance;
}
}