Getter Setter method swift – get and set

By | July 21, 2016

Getter Setter method swift

We have to understand first what getter and setter method is used for. So, we will deal with variables here. When we have a variable whose value we get according to some calculations from class then get method is called and when we want to set its value according to some constraints then use set method.

It can be understood from following example :

In this example, you deal with two variables. sideLength and perimeter. We want to get perimeter when we giveĀ sideLength and we want to set sideLength when we give the perimeter.