structPerson{ var clothes: String { willSet { update(msg: "I'm changing from \(clothes) to \(newValue)") } didSet { update(msg: "I just changed from \(oldValue) to \(clothes)") } } }
funcupdate(msg: String) { print(msg) }
var k =Person(clothes: "T-shirts") k.clothes ="K-shirts"
想要對一個變數進行修改的話可以使用get,這將會得到age後進行修改。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
structCat{ var age: Int var ageInPersonYears: Int { get { return age *7 } } }