Skip to content

Instantly share code, notes, and snippets.

@tempos21ios
Created April 15, 2013 06:44
Show Gist options
  • Save tempos21ios/5386166 to your computer and use it in GitHub Desktop.
Save tempos21ios/5386166 to your computer and use it in GitHub Desktop.
Singleton (manual reference counting)
static MyClass *sharedMyManager = nil;
+ (MyClass*)sharedInstance
{
if (sharedMyManager == nil) {
sharedMyManager = [[super allocWithZone:NULL] init];
}
return sharedMyManager;
}
+ (id)allocWithZone:(NSZone *)zone
{
return [[self sharedInstance] retain];
}
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
- (id)retain
{
return self;
}
- (NSUInteger)retainCount
{
return NSUIntegerMax; //denotes an object that cannot be released
}
- (oneway void)release
{
//do nothing
}
- (id)autorelease
{
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment