黑马程序员技术交流社区
标题:
单例模式的问题?
[打印本页]
作者:
cogddo
时间:
2015-5-14 15:47
标题:
单例模式的问题?
官方推荐的单例模式方案:
+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
if (sharedGizmoManager == nil) {
sharedGizmoManager = [super allocWithZone:zone];
return sharedGizmoManager; // assignment and return on first allocation
}
}
return nil; //on subsequent allocation attempts return nil
}
最后为啥返回 nil,而不是
sharedGizmoManager
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2