Responding to binding updates in SwiftUI

Atikur Rahman
Evangelist Apps Blog
Jun 7, 2022
Picture credit unknown

In Swift, we can use property observers to respond to the change in value of a property as below -

But the same doesn’t work if we use a property wrapper like @State or @Binding with the the property searchTerm. That’s because of the way SwiftUI sends binding updates to the property wrappers. So, if we need to respond to the binding value changes, we need to do something different. There is onChange SwiftUI modifier for that purpose.

Please share your thoughts and suggestions on this article.

Keep up with us on social media:

LinkedIn: https://www.linkedin.com/company/evangelist-apps-limited/

Twitter: https://twitter.com/EvangelistSW/

--

--