/ Published in: Objective C
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
#import "SomeClass.h"
static SomeClass *instance = nil;
@implementation SomeClass
#pragma mark -
#pragma mark Singleton
+ (id)instance
{
@synchronized(self)
{
if (instance == nil)
instance = [[super allocWithZone:NULL] init];
}
return instance;
}
+ (id)allocWithZone:(NSZone *)zone
{
return [[self instance] retain];
}
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
- (id)retain
{
return self;
}
- (unsigned)retainCount {
return UINT_MAX;
}
- (void)release
{
// never release
}
- (id)autorelease
{
return self;
}
- (id)init
{
if (self = [super init])
{
}
return self;
}
@end
Comments
 Subscribe to comments
                    Subscribe to comments
                
                