原理:利用靜態(tài)成員自動滿足dispatch_once規(guī)則
class Singleton {
static let shared = Singleton()
/*
static let shared = {
let instance = Singleton()
return instance
}()
*/
private init(){}
}
利用全局變量自動滿足dispatch_once規(guī)則
private let instance = Singleton()
final class Singleton {
static var shared: Singleton {
instance
}
fileprivate init() {}
}