单例是一种特殊的对象,这个类唯一的对象,单例的几种创建方式
+ (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;
}