美文网首页
iOS单例(方便copy)

iOS单例(方便copy)

作者: A訫飛Flyme | 来源:发表于2017-06-01 11:08 被阅读17次
#import "Singleton.h"

@implementation Singleton
static Singleton* _instance = nil;
+(instancetype) shareInstance
{
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[super allocWithZone:NULL] init] ;
    }) ;
    return _instance ;
}

+(id) allocWithZone:(struct _NSZone *)zone
{
    return [Singleton shareInstance] ;
}

-(void)test
{
    NSLog(@"SAMLI");
}

@end

相关文章

网友评论

      本文标题:iOS单例(方便copy)

      本文链接:https://www.haomeiwen.com/subject/lqgffxtx.html