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#>
    });

 

 

 

 

posted @ 2015-02-26 19:53  myFisland  阅读(175)  评论(0编辑  收藏  举报