简单单例模式的书写
2016-08-25 本文已影响9人
奕十八
‘# 简单的单例
oc:
+(instancetype)sharedInstance
{
static id sharedInstance = nil;
static dispath_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc]init];
});
return sharedInstance;
}
swift:
static let sharedInstance : <#SingletonClass#> = <#SingletonClass#> ()