iOS -- 单例类

#import <Foundation/Foundation.h>

@interface DanLi : NSObject<NSCopying,NSMutableCopying>

@end


@implementation DanLi
+(instancetype)shareDanli{
    static DanLi * dan;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (dan == nil) {
            dan = [[super allocWithZone:nil] init];
        }
    });
    return dan;
}

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

-(id)copyWithZone:(NSZone *)zone{
    return  [DanLi shareDanli];
}

-(id)mutableCopyWithZone:(NSZone *)zone{
    return  [DanLi shareDanli];
}

@end

猜你喜欢

转载自www.cnblogs.com/chebaodaren/p/9291878.html