Created
December 30, 2016 10:47
-
-
Save chriswebb09/44c83bd432445bb2722565c87721f49e to your computer and use it in GitHub Desktop.
Objective-C Singleton
This file contains 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 DataStore : NSObject | |
+ (instancetype)sharedManager; | |
@end |
This file contains 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 "DataStore.h" | |
@implementation DataStore | |
+ (instancetype)sharedManager { | |
static DataStore *sharedInstance = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
sharedInstance = [[DataStore alloc] init]; | |
}); | |
return sharedInstance; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment