Skip to content

Instantly share code, notes, and snippets.

@gonecoding
Created October 11, 2011 15:42
Show Gist options
  • Save gonecoding/1278453 to your computer and use it in GitHub Desktop.
Save gonecoding/1278453 to your computer and use it in GitHub Desktop.
Template for a Shared Instance (Singleton) in Objective-C
+ (NSObject*)sharedInstance;
+ (NSObject*)sharedInstance
{
static NSObject* sharedInstance_;
@synchronized( self )
{
if( !sharedInstance_ )
{
sharedInstance_ = [[NSObject alloc] init];
}
return sharedInstance_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment