Swift willSet didSet y obtener métodos establecidos en una propiedad
Cuál es la diferencia entrewillSet
- didSet
yget
- set
, cuando se trabaja con esto dentro de una propiedad?
Desde mi punto de vista, ambos pueden establecer un valor para una propiedad. Cuándo y por qué debería usarwillSet
- didSet
, y cuandoget
- set
?
Lo se porwillSet
ydidSet
, la estructura se ve así:
var variable1 : Int = 0 {
didSet {
println (variable1)
}
willSet(newValue) {
..
}
}
var variable2: Int {
get {
return variable2
}
set (newValue){
}
}