标签:style c class blog code java
oc中单例模式可以使用以下方法来实现
+ (YourClass *)sharedInstance
{
static dispatch_once_t once;
static YourClass *sharedInstance = nil;
dispatch_once(&once, ^
{
sharedInstance = [[self alooc] init];
});
return sharedInstance;
}
void dispatch_once( dispatch_once_t *predicate, dispatch_block_t block);
如果被多个线程调用,该函数会同步等等直至代码块完成。
AccountManager *accountManager = [AccountManager sharedManager];
AccountManager *accountManager = [[AccountManager alloc] init];
Objective-C单例模式的常用实现,布布扣,bubuko.com
标签:style c class blog code java
原文地址:http://www.cnblogs.com/gongchen/p/3753457.html