I'm trying to change value of Text while typing in TextField. When i type anything in TextField, i want to do some calculation with Textfield value and display it on Text. In Swift, we have func textFieldDidChange(_ textField: UITextField)
delegate method of UITextField to track that UITextField is changed.
In SwiftUI, i tried to create TextField with onEditingChanged
. but somehow it is not going into that block. I don't know if i am doing anything wrong with it or not.
@State var totalAmount: String = ""
@State var addAmount: String = ""
var body: some View {
HStack {
TextField("0.0", text: $totalAmount, onEditingChanged: { _ in
self.addAmount = //doing some calculation with totalAmount
})
Text(self.addAmount)
}
}
Can anyone help with this?