Created
March 19, 2014 23:47
-
-
Save dniswhite/9654152 to your computer and use it in GitHub Desktop.
objective c simple 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
// Created by Dennis White | |
// Copyright (c) 2014 dniswhite. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface SingletonManager : NSObject | |
+(id) sharedSingletonManager; | |
@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
// Created by Dennis White | |
// Copyright (c) 2014 dniswhite. All rights reserved. | |
// | |
#import "SingletonManager.h" | |
@implementation SingletonManager | |
+(id) sharedSingletonManager | |
{ | |
static SingletonManager * singletonManager = nil; | |
static dispatch_once_t runOnce; | |
dispatch_once(&runOnce, ^{ | |
singletonManager = [[self alloc] init]; | |
}); | |
return self; | |
} | |
-(id) init | |
{ | |
if (self = [super init]) { | |
// init stuff here | |
} | |
return self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment