前端之家收集整理的这篇文章主要介绍了
Swift入坑--单例,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
class func sharedInstance() -> ClassName {
struct singleton{
static var once: dispatch_once_t = 0
static var instance: <span style="font-family: Arial,Helvetica,sans-serif;">ClassName</span><span style="font-family: Arial,sans-serif;">? = nil</span>
}
dispatch_once(&singleton.once,{
singleton.instance = <span style="font-family: Arial,sans-serif;">ClassName</span>()
}
)
return singleton.instance!
}
原文链接:https://www.f2er.com/swift/326660.html