2019-05-16 星期四 5 of 7

  • blend (verb)

to combine different things in a way that produces a pleasant result.

a story that blends story and legend.
blend the sugar,eggs and flour

  • 绝对的单例方法

static NSObject *_instance = nil;

锁住alloc方法,锁住init方法,锁住copy方法,才能保证是全局唯一单例

//锁定 alloc方法
+(id)allocWithZone:(struct _NSZone *)zone{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super allocWithZone:zone];
    });
    return _instance;
}
//锁定init方法
-(instancetype)init{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [super init];
    });
    return _instance;
}
//锁定copy
- (id)copyWithZone:(NSZone __unused*)zone {
    return _instance;
}
//锁定 mutable copy
- (id)mutableCopyWithZone:(NSZone __unused*)zone {
    return _instance;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容