首页 > 代码库 > Swift单例的写法

Swift单例的写法

Swift单例的写法

by 伍雪颖

override func viewDidLoad() {
        super.viewDidLoad()
        let instance = SingletonClass.shared
    }
    
    class SingletonClass {
        class var shared: SingletonClass {
            struct Static {
                static let instance: SingletonClass = SingletonClass()
                }
                return Static.instance
            }
}