Last active
August 29, 2015 14:07
-
-
Save AdamRobertsEF/c1b68f598935c71abe55 to your computer and use it in GitHub Desktop.
Autoconfiguring singleton objective-c class method
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 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