swift init 初始化

class PropertiesClass1 {
    var a = "Stringa"
    init() {
        print("初始化")
    }


}

class PropertiesClass2 {
    var id  = 0
    //lazy 懒加载,只有使用的时候才触发
    lazy var properties1 = PropertiesClass1()

    //初始化必须全部初始化所有属性,或者为Options
    var name: String? 

    //geter seter
    var qq: String {
        //geter seter 里面不能使用自己属性,否则会死循环
        get {
            return self.name!
        }
        set {
            self.name = newValue
        }
    }
    //只读属性
    var height: Int {
        return 180
    }

    var address: String = "xxx" {
        willSet {
            print(" 新值(newValue)")
        }

        didSet {
            print("旧值 (oldValue)")
        }
    }

    var function_properties = {return "properties"}()

    
}

var properties2 = PropertiesClass2()

print(properties2.properties1)


properties2.qq = "65683264"
print(properties2.qq)

print(properties2.height)
// properties2.height = 2

properties2.address = "ca"

print(properties2.function_properties)
原文地址:https://www.cnblogs.com/miss-once/p/5213840.html