I know how to set 'setter' of an stored property to private (e.g. public private(set) var name: String = "John"
) but how do we set 'setter' of an computed property to private? In this case the 'setter' for the variable 'age
'. When I tried to put an keyword private in front of set(newAge){}
, XCode display an error. So is it possible to set 'setter' of an computed property to private?
public class Person {
public private(set) var name: String = "John"
var age: Int{
get {
return 10
}
set(newAge){ // how to set this setter to private so to restrict modification
}
}
}