Skip to content

Instantly share code, notes, and snippets.

@antoniocasero
Created July 14, 2013 09:57
Show Gist options
  • Save antoniocasero/5993793 to your computer and use it in GitHub Desktop.
Save antoniocasero/5993793 to your computer and use it in GitHub Desktop.
Weak Singleton
+ (id)sharedInstance
{
static __weak ASingletonClass *instance;
ASingletonClass *strongInstance = instance;
@synchronized(self) {
if (strongInstance == nil) {
strongInstance = [[[self class] alloc] init];
instance = strongInstance;
}
}
return strongInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment