Skip to content

Instantly share code, notes, and snippets.

@dickbrouwer
Created April 12, 2012 16:19
Show Gist options
  • Save dickbrouwer/2368787 to your computer and use it in GitHub Desktop.
Save dickbrouwer/2368787 to your computer and use it in GitHub Desktop.
Create singleton using dispatch_once_t
+ (UserManager *)sharedManager {
static dispatch_once_t once;
dispatch_once(&once, ^ {
_sharedManager = [[self alloc] init];
});
return _sharedManager;
}
@egold
Copy link

egold commented Feb 28, 2014

This happened for me during initialization of a static NSMutableArray in +initialize. Was very frustrating to track down - thanks for your post!

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