I was using the onChange(of:perform:) SwiftUI modifier. I then wanted to get the old value, to compare it with the new value. I read the documentation, which says:
The previous value may be captured by the closure to compare it to the new value.
With an example:
.onChange(of: playState) { [playState] newState in
model.playStateDidChange(from: playState, to: newState)
}
My question is why in the example is playState captured in the [ ]? The playState value could easily be accessed without passing it in. In addition, this isn't part of a class, so I assume there is no way to create a strong reference by capturing self of some sort.
Why is the example written like this?