iOS开发-单例GCD

+ (SingletonObject *)shareInstance;


+ (SingletonObject *)shareInstance {

    static SingletonObject *__singletion;

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        __singletion=[[self alloc] init];

    });

    return __singletion;

}

static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        <#code to be executed once#>
    });

 

 
原文地址:https://www.cnblogs.com/fisland/p/4302029.html