Advertisement
priore

Singleton with Grand Central Dispatch (GCD)

Nov 8th, 2012
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Singleton with Grand Central Dispatch (GCD)
  2. // declare the static variable outside of the singleton method
  3. static MyClass *__sharedMyClass = nil;
  4.  
  5. + (MyClass *)singleton
  6. {
  7.     static dispatch_once_t once = 0;
  8.     dispatch_once(&once, ^{__sharedMyClass = [[self alloc] init];});
  9.     return __sharedMyClass;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement