码迷,mamicode.com
首页 > 其他好文 > 详细

OC中使用单例模式

时间:2014-10-28 21:13:03      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   sp   div   on   log   new   


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中使用单例模式

标签:style   blog   color   使用   sp   div   on   log   new   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!