+ 2
Why recursion does not occur, when I assign a value to a property within its own didSet observe?
Here is the code: class StepCounter { var totalSteps: Int = 0 { willSet(newSteps) { print("About to set totalSteps to \(newSteps)") } didSet { totalSteps+=10// I thought recursion should occur (willSet and didSet should be called every time) print ("\(totalSteps - oldValue) steps") } } } let stepCounter = StepCounter() stepCounter.totalSteps = 50
1 ответ
+ 1
I guess that's how Swift was designed. The official Apple documentation says: "If you assign a value to a property within its own didSet observer, the new value that you assign replaces the one that was just set."