Property Observers
Swift provides an interesting feature called property observation. Property observers watch for and respond to changes in a given property. Property observation is available to any stored property that you define and is also available to any property that you inherit. You cannot use property observers with computed properties that you define. (But you have full control over the definition of a computed property’s setter and getter and can respond to changes there.)
Imagine that the citizens of your beleaguered town are getting restless. They demand that the mayor do something to protect them from the monstrous pox patrolling the countryside. The mayor’s first action is to track the attacks on the townspeople. Property ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access