0 votes
in ios by (190 points)
retagged by

2 Answers

0 votes
by (290 points)
Property observers observe and respond to changes in a property's value. Property observers are called every time a property's value is set, even if the new value is the same as the property's current value.
0 votes
by (380 points)

Being able to observe changes in various values is essential for many different kinds of programming styles and techniques. Whether we’re using delegates, functions, or reactive programming — much of our logic is often driven by changes in states and values.

There are two very appropriately named property observers in Swift: willSet, and didSet. They are called exactly when you think they would be, right before and right after setting, respectively. On top of this, they are also implicitly given constants describing the newValue and oldValue respectively.

Welcome to Reubro Q&A, where you can ask questions and receive answers from other members of the community.
...