单例

2017-09-11  本文已影响4人  阶梯

.h中,遵循协议,暴露方法

@interface DJTools : NSObject<NSCopying>

+(DJTools *)shareDJTools;

-(void)showLogInfo;

@end

.m中

static DJTools *djTools = nil;

+(DJTools *)shareDJTools{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        djTools = [[super allocWithZone:NULL] init];
    });
    return djTools;
}


-(void)showLogInfo{
    NSLog(@"我写了单例");
}

+(id)allocWithZone:(struct _NSZone *)zone{
    return [DJTools shareDJTools];
}

-(id)copyWithZone:(NSZone *)zone{
    return [DJTools shareDJTools];
}


上一篇下一篇

猜你喜欢

热点阅读