
Swift — didSet, the power of observer
“didSet” is a simple property observers in swift. This story, I will using didSet to auto update UI whenever property value is change.
Normally, when we need to update UI family like UILabel in IOS development, we can asign code wherever state that we need to update your UI such as “ showLabel.text = “Hello World” ”. In the other hand, there is accomplish to auto update UI when we change variable value. It mean, we didn’t have to concern about where we coding to update data. Because of UI always auto update whenever your variable value is change.
For example, we have UILabel that display the random number and random button. Whenever we tap random button, random number will display on label. Certainly, we must use didSet to update your label.

On above, whenever property value(num) is change, didSet will responsive and update label (Note: disSet isn’t called when first initializer.). Wow, so nice. It’s very easy and clearly. I wish you will love to using didSet like me. Thank you for reading. :)