10
Créez un singleton à l'aide de dispatch_once de GCD dans Objective-C
Si vous pouvez cibler iOS 4.0 ou supérieur À l'aide de GCD, est-ce le meilleur moyen de créer un singleton en Objective-C (thread safe)? + (instancetype)sharedInstance { static dispatch_once_t once; static id sharedInstance; dispatch_once(&once, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; }