Swift学习笔记

Swift - 单例

2022-05-14  本文已影响0人  aven_kang
private let shareInstanceTest = testShareInstance()

class testShareInstance {
    
    var age:Int = 0
    
    class var shareInstance : testShareInstance {
        
        return shareInstanceTest
    }
    
}
        let share1 = testShareInstance.shareInstance
        share1.age = 20
        let share2 = testShareInstance.shareInstance
        share2.age = 30
        print(share1.age) // 30
        print(share2.age) // 30
上一篇下一篇

猜你喜欢

热点阅读