Skip to content

Instantly share code, notes, and snippets.

@nanzhipro
Forked from antoniocasero/WeakSingleton
Created August 3, 2017 03:33
Show Gist options
  • Save nanzhipro/81df1dff7eceb50f2df27ffae1fe1e4a to your computer and use it in GitHub Desktop.
Save nanzhipro/81df1dff7eceb50f2df27ffae1fe1e4a 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