You can also use the didSet
to set the variable to a different value. This does not cause the observer to be called again as stated in Properties guide. For example, it is useful when you want to limit the value as below:
let minValue = 1var value = 1 { didSet { if value < minValue { value = minValue } }}value = -10 // value is minValue now.