Skip to content

Instantly share code, notes, and snippets.

@dniswhite
Created March 19, 2014 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dniswhite/9654152 to your computer and use it in GitHub Desktop.
Save dniswhite/9654152 to your computer and use it in GitHub Desktop.
objective c simple singleton
// Created by Dennis White
// Copyright (c) 2014 dniswhite. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface SingletonManager : NSObject
+(id) sharedSingletonManager;
@end
// 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