//基於gcd的單例模式
static Type *_instances; + (id)allocWithZone:(NSZone *)zone { static dispatch_once_t onceToken; dispatch_once(&onceToken,^{ _instances = [super allocWithZone:zone]; }); return _instances; } //創建一個獲取單例的方法 + (Type *)sharedInstances { if(_instances == nil){ _instances = [[self alloc] init]; } return _instances; }