Swift: Computed property getter and setter

Computed property provides a getter and optional setter. When we try to access the computed property, the getter code is called. When we set a new value or modify the value of a computed property the setter code is called. The setter code is optional.

In the below code, we we try to read the computed property, the getter code is called. When we try to insert a value to modify the computed property, the setter code is called.

Leave a Reply