单例模式

OC中

static Tools *_instance;
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[super allocWithZone:zone]init];
    });
    return _instance;
}

+ (instancetype)shareInstance {
    return [[Tools alloc]init];
}

你可能感兴趣的:(单例模式)