原理:利用静态成员自动满足dispatch_once规则
class Singleton {
static let shared = Singleton()
/*
static let shared = {
let instance = Singleton()
return instance
}()
*/
private init(){}
}
利用全局变量自动满足dispatch_once规则
private let instance = Singleton()
final class Singleton {
static var shared: Singleton {
instance
}
fileprivate init() {}
}
网友评论