Last active
January 2, 2016 21:19
-
-
Save alexcristea/8362307 to your computer and use it in GitHub Desktop.
Objective-C Singleton implementation using Grand Central Dispatch (GCD) framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface SingletonObject : NSObject | |
+ (id)sharedInstance; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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