您的位置:首页 > 其它

单例的完整写法

2015-08-20 17:19 337 查看
iOS

#pragma mark - singleton

static EmailLoginController *sharedInstance = nil;

+ (EmailLoginController*)sharedInstance {

@synchronized (self) {

if (!sharedInstance) {

sharedInstance = [[EmailLoginController alloc] init];

}

}

return sharedInstance;

}

+ (id)allocWithZone:(struct _NSZone *)zone {

@synchronized (self) {

if (!sharedInstance) {

sharedInstance = [super allocWithZone:zone];

}

}

return sharedInstance;

}

- (id)copyWithZone:(NSZone *)zone {

return sharedInstance;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: