Skip to content

Instantly share code, notes, and snippets.

@markSci5
Created July 2, 2013 02:50
Show Gist options
  • Save markSci5/5906449 to your computer and use it in GitHub Desktop.
Save markSci5/5906449 to your computer and use it in GitHub Desktop.
iOS Singleton
#import <Foundation/Foundation.h>
@interface MySingleton : NSObject
- (id)sharedInstance;
@end
#import "MySingleton.h"
@implementation MySingleton
- (id)sharedInstance
{
static dispatch_once_t pred;
__strong static MySingleton *shared = nil;
dispatch_once(&pred, ^{
shared = [[MySingleton alloc] init];
});
return shared;
}
@end
@markSci5
Copy link
Author

markSci5 commented Jul 2, 2013

Code snippet for creating a singleton using GCD in iOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment