标签:
方式一: (类似OC)
class SingletonDispatch{
class var shareInstance : SingletonDispatch {
//结构体
struct Static {
static var onceToken : dispatch_once_t = 0
static var instance : SingletonDispatch? = nil
}
//创建
dispatch_once(&Static.onceTokec){
Static.instance = SingletonDispatch()
}
return Static.instance!
}
}
方式二:
class SingletonDispatch {
class shareInstance : SingletonDispatch {
struct Static {
static var instance = SingletonDispatch()
}
return Static.instance
}
}
方式三:
class SingletonDispatch {
static let share Instance = SingletonDispatch()
private init() {}
}
//单例的创建
let single = SingletonDispatch.shareInstance
标签:
原文地址:http://www.cnblogs.com/daxueshan/p/5588485.html