十一岁的加重songxing10000…… ------ 回到博主首页

单例写法

static id sharedInstance = nil;
+ (instancetype)sharedInstance {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [super allocWithZone:zone];
    });
    return sharedInstance;
}

 

posted @ 2016-03-19 18:53  songxing10000  阅读(122)  评论(0编辑  收藏  举报