Day.02.17 单例练习

Main.m
#import 

#import "Mao.h"

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

Mao.h
@interface Mao : NSObject

+ (Mao *)tiger;

@end

Mao.m
#import "Mao.h"

@implementation Mao

static Mao *panda = nil;

+ (Mao *)tiger {

    if (panda == nil) {
        
        panda = [[Mao alloc]init];
    }
    
    return panda;
}


@end

2016-02-17 14:51:01.444 单例练习[1071:58841] 
2016-02-17 14:51:01.446 单例练习[1071:58841] 
Program ended with exit code: 0

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