0
What is the point of Getters and Setters? What do they do?
2 Respuestas
+ 1
Getters and Setters a common functions / methods to get or set values of class members or fields in a controllable way.
Examples:
--
class Person {
    // field of class Person which is called age
    var age:Int = 0
    // getter for age
    public func getAge() -> Int {
        return self.age
    }
    // setter for age (only values greater zero are accepted)
    public func setAge(age:Int) {
        if age > 0 {
            self.age = age
        }
    }
}
0
when you use those func you  can do something to the value. as the setAge function you could check age illegible or not.



