摘要: 一个共享单例只是一个用类方法容易获得的特定实例,通常存储在一个静态变量中。有很多方法可以实现共享单例,但我的建议是使用Grand Central Dispatch(GCD): 1 + (MYSingleton *)sharedSingleton { 2 static dispatch_once_t pred; 3 static MYSingleton *instance = nil; 4 dispatch_once(&pred, ^{instance = [[self alloc] init];}); 5 return instance; 6 }这样编写方便、速度快,而且线程安... 阅读全文
posted @ 2013-05-01 15:07 疯狂の小石子 阅读(216) 评论(0) 推荐(0) 编辑