#import "EOCClassShareInstance.h" @implementation EOCClassShareInstance /** * 通常建立單例方式 */ +(id)shareInstance{ static EOCClassShareInstance *shared = nil; @synchronized(self) { if (!shared){ shared = [[EOCClassShareInstance alloc]init]; } } return shared; } /** * GCD線程安全模式 */ +(id)sharedGCDInstance{ static EOCClassShareInstance *sharedGCD = nil; static dispatch_once_t onceToken;//每次調用都必須使用相同的標記,因此要申明爲static dispatch_once(&onceToken, ^{ sharedGCD = [[self alloc]init]; }); return sharedGCD; } @end