加锁的写法:
static id sharedMyManager;
+ (id)sharedThemeManager
{
@synchronized(self)
{
if(sharedMyManager == nil)
{
sharedMyManager = [[self alloc] init];
}
}
return sharedMyManager;
}
第一次实例化创建Lock free:
static id sharedMyManager;
+ (void)initialize
{
static BOOL initialized = NO;
if (initialized == NO) {
initialized = YES;
sharedMyManager = [[self alloc] init];
}
}
static id sharedMyManager;
+ (id)sharedManager
{
static dispatch_once_t once;
dispatch_once(&once, ^{sharedMyManager = [[self alloc] init];});
return sharedMyManager;
}
{
return [self sharedManager];
}
+ (id)copyWithZone:(struct _NSZone *)zone
{
return self;
}