Skip to content

Instantly share code, notes, and snippets.

@chriswebb09
Created December 30, 2016 10:47
Show Gist options
  • Save chriswebb09/44c83bd432445bb2722565c87721f49e to your computer and use it in GitHub Desktop.
Save chriswebb09/44c83bd432445bb2722565c87721f49e to your computer and use it in GitHub Desktop.
Objective-C Singleton
#import <Foundation/Foundation.h>
@interface DataStore : NSObject
+ (instancetype)sharedManager;
@end
#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