Created
April 12, 2012 16:19
-
-
Save dickbrouwer/2368787 to your computer and use it in GitHub Desktop.
Create singleton using dispatch_once_t
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
+ (UserManager *)sharedManager { | |
static dispatch_once_t once; | |
dispatch_once(&once, ^ { | |
_sharedManager = [[self alloc] init]; | |
}); | |
return _sharedManager; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This happened for me during initialization of a static NSMutableArray in +initialize. Was very frustrating to track down - thanks for your post!