單例模式
class MyClass{
let name = "sss"
class func shareInstance()->MyClass{
struct YRSingleton{
static var predicate:dispatch_once_t = 0
static var instance:MyClass? = nil
}
dispatch_once(&YRSingleton.predicate,{
YRSingleton.instance = MyClass()
}
)
return YRSingleton.instance!
}
}
訪問
NSLog("%@", MyClass.shareInstance().name)