Skip to content

Instantly share code, notes, and snippets.

@mikeash
Created July 13, 2010 01:10
Show Gist options
  • Save mikeash/473310 to your computer and use it in GitHub Desktop.
Save mikeash/473310 to your computer and use it in GitHub Desktop.
+ (id)sharedInstance {
id singleton = objc_getAssociatedObject(...);
if(!singleton) {
[lock lock];
singleton = objc_getAssociatedObject(...);
if(!singleton)
objc_setAssociatedObject([[self alloc] init], ...);
[lock unlock];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment