单例类

Animal.h

+ (instancetype)shareAnimal;

Animal.m

+ (instancetype)shareAnimal{

    static Animal *animal = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        animal = [[Animal alloc]init];
    });
    
    return animal;
}

你可能感兴趣的:(单例类)