Use property observers

Swift

Use Swift's property observers to observe and respond to changes in a property’s value. Both `willSet` and `didSet` takes a default parameter to get new and old values
var language: String = "ObjC" { willSet(newValue) { print("willSet \(language) to \(newValue)") } didSet(oldValue) { print("didSet \(oldValue) to \(language)") } } language = "Swift" /* prints: willSet ObjC to Swift didSet ObjC to Swift */