当前位置: 代码迷 >> Iphone >> 单例的创办
  详细解决方案

单例的创办

热度:159   发布时间:2016-04-25 05:31:34.0
单例的创建

单例是一种特殊的对象,这个类唯一的对象,单例的几种创建方式

+ (Singleton *)shareSingleton {

static Singleton *single = nil;

保证线程只走一次

static dispatch_once_t oneToken;

dispatch_once(&oneToken,^{

single = [Singleton alloc]init];

});

return single;
}

+ (Singleton *)shareSingleton {
static Singleton *single;
if (single  == nil) {
   single = [Singleton alloc]init];
}

 return single;

}

 

  相关解决方案