Does this singleton pattern make sense?
- by dontWatchMyProfile
@implementation MySingletonClass
static MySingletonClass *sharedInstance = nil;
+ (MySingletonClass*)sharedInstance {
@synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [[self alloc] init];
}
}
return sharedInstance;
}
+ (id)alloc {
@synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [super alloc];
return sharedInstance;
}
}
return nil;
}
+ (id)allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [super allocWithZone:zone];
return sharedInstance;
}
}
return nil;
}
-(id)init {
self = [super init];
if (self != nil) {
// initialize stuff here
}
return self;
}
@end
Not sure if it's ok to overwrite both alloc and allocWithZone: like this...?