When creating a class, what is the difference between these 2 implementations of creating a custom class in regards to security. They both work the exact same as far as I've used them, but have heard using private variables is the proper way to create classes
class Person {
var name:String
var age:Int
init(name: String, age: Int){
self.name = name
self.age = age
}
}
and
class Person {
private var _name: String
private var _age: Int
var name: String {
set {
self._name = newValue
} get {
return _name
}
}
var age: Int {
set {
self._age = newValue
} get {
return _age
}
}
init(name: String, age: Int){
self._name = name
self._age = age
}
}