Skip to content

Instantly share code, notes, and snippets.

@mergesort
Created March 17, 2014 18:08
Show Gist options
  • Save mergesort/9604935 to your computer and use it in GitHub Desktop.
Save mergesort/9604935 to your computer and use it in GitHub Desktop.
The Perfect Singleton
A singleton which you can drop into any class without having to change a line of code no matter the class, no macros needed.
//.h
+ (instancetype)sharedRuntimeController;
//.m
+ (instancetype)sharedRuntimeController
{
static id _sharedRuntimeController = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedRuntimeController = [[[self class] alloc] init];
});
return _sharedRuntimeController;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment