
#import "MyHandle.h" static MyHandle *handle = nil;
@implementation MyHandle
// 传统写法
// 此时如果多个任务并发执行,他就不会满足单例的优点
//+ (MyHandle *)shareMyHandle {
// if (nil == handle) {
// handle = [[MyHandle alloc] init];
// }
// return handle;
//} // 多线程中的写法
+ (MyHandle *)shareMyHandle {
// 在GCD 中保证只执行一次, 用于记录内容是否执行过
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
handle = [[MyHandle alloc] init];
});
return handle;
} @end