iOS 多线程编程<七、GCD单例宏>

来源:互联网 发布:mac类似powerdesigner 编辑:程序博客网 时间:2024/06/05 02:04

把单例定义在宏里,方便以后创建单例时候调用。

////  Singleton.h//  Singleton////  Created by fe on 2016/10/19.//  Copyright © 2016年 fe. All rights reserved.//#define singletonH + (instancetype)shareInstance;#define singletonM static id _instance;\+(instancetype)allocWithZone:(struct _NSZone *)zone\{\    static dispatch_once_t onceToken;\    dispatch_once(&onceToken, ^{\        _instance = [super allocWithZone:zone];\    });\    return _instance;\}\+ (instancetype)shareInstance\{\    return [[self alloc] init];\}\- (id)copyWithZone:(nullable NSZone *)zone\{\    return _instance;\}\- (id)mutableCopyWithZone:(nullable NSZone *)zone\{\    return _instance;\}


0 0