Objective-C でシングルトンパターン(Singleton)のサンプルコード

サンプルコード:
static Config * instance = nil;
+(Config *) Instance
{
@synchronized(self)
{
if(nil == instance)
{
[self new];
}
}
return instance;
}

+(id)allocWithZone:(NSZone *)zone
{
@synchronized(self)
{
if(instance == nil)
{
instance = [super allocWithZone:zone];
return instance;
}
}
return nil;
}

IOS

Posted by arkgame