首页 > 其他 > 详细

OC中使用单例模式

时间:2014-10-28 21:12:30      阅读:279      评论:0      收藏:0      [点我收藏+]

1
static Config * instance = nil; 2 +(Config *) Instance 3 { 4 @synchronized(self) 5 { 6 if(nil == instance) 7 { 8 [self new]; 9 } 10 } 11 return instance; 12 } 13 14 +(id)allocWithZone:(NSZone *)zone 15 { 16 @synchronized(self) 17 { 18 if(instance == nil) 19 { 20 instance = [super allocWithZone:zone]; 21 return instance; 22 } 23 } 24 return nil; 25 }

OC中使用单例,比如全局配置,全局属性能可以采用此方法,注意要实现allocWithZone方法

OC中使用单例模式

原文:http://www.cnblogs.com/iSeven/p/4057643.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!