Skip to content

Instantly share code, notes, and snippets.

@ArchieR7
Last active May 4, 2017 06:23
Show Gist options
  • Save ArchieR7/5f5f8e7445e44d84a29391fb2e4dd37a to your computer and use it in GitHub Desktop.
Save ArchieR7/5f5f8e7445e44d84a29391fb2e4dd37a to your computer and use it in GitHub Desktop.
Singleton by Objective-C
#import <UIKit/UIKit.h>
@interface SingletonDemo : NSObject
+ (instancetype)shared;
@end
#import "SingletonDemo.h"
@implementation SingletonDemo
+ (instancetype)shared {
static SingletonDemo *instance = nil;
static dispatch_once_t once_token;
dispatch_once(&once_token, ^{
instance = [[SingletonDemo alloc] init];
});
return instance;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment