Created
January 2, 2016 18:16
-
-
Save MaximAlien/6eccab5066b4c8b1cbda to your computer and use it in GitHub Desktop.
[Objective-C] Singleton Design Pattern
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
// Singleton.h | |
#import <Foundation/Foundation.h> | |
@interface Singleton : NSObject | |
+ (Singleton *)sharedInstance; | |
@end | |
// Singleton.m | |
#import "Singleton.h" | |
@implementation Singleton | |
+ (Singleton *)sharedInstance | |
{ | |
static id sharedInstance; | |
static dispatch_once_t oncePredicate; | |
dispatch_once(&oncePredicate, ^{ | |
sharedInstance = [[Singleton alloc] init]; | |
}); | |
return sharedInstance; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment