Skip to content

Instantly share code, notes, and snippets.

@alexcristea
Last active January 2, 2016 21:19
Show Gist options
  • Save alexcristea/8362307 to your computer and use it in GitHub Desktop.
Save alexcristea/8362307 to your computer and use it in GitHub Desktop.
Objective-C Singleton implementation using Grand Central Dispatch (GCD) framework
#import <Foundation/Foundation.h>
@interface SingletonObject : NSObject
+ (id)sharedInstance;
@end
#import "SingletonObject.h"
@implementation SingletonObject
+ (id)sharedInstance
{
static dispatch_once_t onceToken;
static id sharedInstance;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment