Is "a new version of the closure" an accurate description?

I read the following in SwiftUI View.onChange document (emphasis mine):

When the value changes, the new version of the closure will be called, so any captured values will have their values from the time that the observed value has its new value.

While I understand what it means, the description doesn't fit my mental model. In my understanding, a closure has only one version, the things that change are its captured values located in heap. Out of curiosity, I also google the term and find only SwiftUI onChange document uses it. So perhaps the description is inaccurate? (though I can't suggest a better way to express it either).

1 Like

View appears -> body is called, includes initial version of block -> state changes -> body is called again, includes new version of the block

So if you capture a struct in that block, it will always capture the current state of it instead of the one when the body was first called.

.onChange() { [someValue] in
  ...
}
3 Likes