Skip to content

Instantly share code, notes, and snippets.

@AdamRobertsEF
Last active August 29, 2015 14:07
Show Gist options
  • Save AdamRobertsEF/c1b68f598935c71abe55 to your computer and use it in GitHub Desktop.
Save AdamRobertsEF/c1b68f598935c71abe55 to your computer and use it in GitHub Desktop.
Autoconfiguring singleton objective-c class method
// Created by Adam Roberts on 13/10/2014 BSD License
// Place in .h file in @interface section
+(instancetype)sharedManager;
// Place in .m file in @implementation section
+(instancetype)sharedManager{
static dispatch_once_t pred;
static id sharedManager = nil;
dispatch_once(&pred, ^{
sharedManager = [[[self class] alloc] init];
});
return sharedManager;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment