摘要: 单例模式算是开发中比较常见的一种模式了。在iOS中,单例有两种实现方式(至少我目前只发现两种)。根据线程安全的实现来区分,一种是使用@synchronized,另一种是使用GCD的dispatch_once函数。要实现单例,首先需要一个static的指向类本身的对象,其次需要一个初始化类函数。下面是两种实现的代码。1、@synchronizedstatic InstanceClass *instance;+ (InstanceClass *)defaultInstance{ @synchronized (self){ if (instance == nil) { ... 阅读全文
posted @ 2013-11-12 11:34 ccguo 阅读(649) 评论(0) 推荐(0) 编辑
我要啦网店统计