Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value change update on Binding in SwiftUI [duplicate]

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?

like image 775
Sikander Avatar asked Sep 11 '25 14:09

Sikander


1 Answers

Use this instead:

.onChange(of: pinValue) { output in
  print(output)
}
like image 98
Asperi Avatar answered Sep 13 '25 04:09

Asperi