1 //GCD单例 2 +(instancetype)share 3 { 4 //整个生命周期只创建一次 5 static GCDSingleton *object = nil; 6 static dispatch_once_t onceToken; 7 dispatch_once(&onceToken,^{ 8 object = [[GCDSingleton alloc] init]; 9 }); 10 return object; 11 } 12 //synchonized单例 13 +(instancetype)defaultManager 14 { 15 static GCDSingleton *object = nil; 16 17 @synchronized(self) { 18 if (object == nil) { 19 object = [[GCDSingleton alloc] init]; 20 } 21 22 } 23 return object; 24 } 25 @end