Day.01.16 单例练习

main.m
#import 

#import "She.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        She *tiger = [She mao];
        
        NSLog(@"%@",tiger);
        
        NSLog(@"%@",[She mao]);
        
    }
    return 0;
}


.h文件
+ (She *)mao;


.m文件
static She *tiger = nil;

+ (She *)mao{

    if (tiger == nil) {
        
        tiger = [[She alloc]init];
    }

    return tiger;
}
多写几遍   面试肯定用

你可能感兴趣的:(Day.01.16 单例练习)