|
[Objective-C] Singleton with Grand Central Dispatch (GCD) |
|
 |
// Singleton with Grand Central Dispatch (GCD)
// declare the static variable outside of the singleton method
static MyClass *__sharedMyClass = nil;
+ (MyClass *)singleton
{
static dispatch_once_t once = 0;
dispatch_once(&once, ^{__sharedMyClass = [[self alloc] init];});
return __sharedMyClass;
}
|
|
|
|
|
|
|
|
Copyright © 1996-2022 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581. |
|
|
|