Day.01.18 单例练习

main.h
#import 

#import "Mao.h"

int main(int argc, const char * argv[]) {

    Mao *panda = [Mao tiger];
    
    NSLog(@"%@",panda);
    
    NSLog(@"%@",[Mao tiger]);
    
    return 0;
}

.h
+ (Mao *)tiger;

.m
#import "Mao.h"

@implementation Mao

static Mao *panda = nil;

+ (Mao *)tiger {

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

@end


2016-01-18 20:48:39.167 单例练习[4197:632589] 
2016-01-18 20:48:39.168 单例练习[4197:632589] 
Program ended with exit code: 0

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