18.单例模式写法

#import"Singleton.h"
 
@implementationSingleton
 
static Singleton* _instance = nil;
 
+(instancetype) shareInstance
{
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[superallocWithZone:NULL] init] ;
    }) ;
     
    return_instance ;
}
 
+(id) allocWithZone:(struct _NSZone *)zone
{
    return[Singleton shareInstance] ;
}
 
-(id) copyWithZone:(struct _NSZone *)zone
{
    return[Singleton shareInstance] ;
}
 
@end

你可能感兴趣的:(18.单例模式写法)