单例的完整写法
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;
}
#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;
}
相关文章推荐
- 对于公司网站架构的一些感慨~
- Android L 5.0版本获取topActivity的方法
- iOS时间处理之时间对比 by Nicky.Tsui
- JPA & Hibernate 注解
- 调试lldb命令常用
- Java jdbc事物回滚处理,纯手工打造
- twistd内置服务
- dilate函数
- 40个高质量Java开发者博客
- DOM(三)-01-(示例-邮件列表)
- 读取bq26500电池电量 Driver
- Oracle自增序列
- struts2用户是否登录拦截器,拦截之后异步跳转到登录页面
- 【转】Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- 安卓突击:Android 动画有哪几种?
- 如何识别真正的程序员
- 基于 OpenFlow 实现网络虚拟化
- linux挂载
- Android性能优化之内存篇-google
- POJ 3984:迷宫问题【BFS】