Understanding property observers

Each superhero has a running speed score that determines how fast he will move when running; therefore, we will add a public runningSpeedScore property. We will change the initializer code to set an initial value for the new property. However, this new property has some specific requirements.

Whenever the running speed score is about to change, it will be necessary to trigger a few actions. In addition, we have to trigger other actions after the value for this property changes. We might consider adding code to a setter method combined with a related property, run code before we set the new value to the related property, and then run code after we set the new value. However, Swift allows us to take advantage of property ...

Get Swift 3 ObjectOriented Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.