-
-
Save nanzhipro/81df1dff7eceb50f2df27ffae1fe1e4a to your computer and use it in GitHub Desktop.
Weak Singleton
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
+ (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