Home > Software design >  Get value change update on Binding in SwiftUI
Get value change update on Binding in SwiftUI

Time:06-03

I have a binding on my SwiftUI view

@Binding var pinValue: String

I want to get update every time the value is changed. I tried below as I'd do on a publisher but I'm getting errors because it's not a publisher.

.onReceive($pinValue, perform: { output in
            print(output)
        })

I've also tried to access $pinValue.publisher but the .onReceive block wont' work.

How can I get an update every time the value of pinValue is changed?

CodePudding user response:

Use instead

.onChange(of: pinValue) { output in
  print(output)
}
  • Related