
sokie singleton OB C
By: a guest on
May 2nd, 2012 | syntax:
Objective C | size: 0.73 KB | hits: 26 | expires: Never
#import "Singleton.h"
@implementation Singleton
static Singleton *sharedSingleton =nil;
+ (Singleton *) sharedSingleton
{
if (sharedSingleton == nil)
{
sharedSingleton = [[super allocWithZone:NULL] init];
}
return sharedSingleton;
}
+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self)
{
if (sharedSingleton == nil)
{
sharedSingleton = [super allocWithZone:zone];
return sharedSingleton;
}
}
return nil;
}
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
- (id)retain
{
return self;
}
- (NSUInteger)retainCount
{
return NSUIntegerMax;
}
- (void) release
{
}
- (id)autorelease
{
return self;
}
@end