美文网首页
2019-05-16 星期四 5 of 7

2019-05-16 星期四 5 of 7

作者: 老布威利斯 | 来源:发表于2019-05-16 10:09 被阅读0次
  • 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;
}

相关文章

网友评论

      本文标题:2019-05-16 星期四 5 of 7

      本文链接:https://www.haomeiwen.com/subject/kcsbaqtx.html