Reputation: 89
I am creating a form and I need to track the last character entered. I know I can use onChange to detect when the text field changed, but it displays the while string and not just the last character. Any feedback is appreciated!
import SwiftUI
struct AddAssetView: View {
@State private var costTextField = ""
var body: some View {
VStack {
NavigationView {
Form {
Section {
TextField("Cost", text: $costTextField)
.keyboardType(.numberPad)
.onChange(of: costTextField, perform: { value in
print(value)
})
}
}.navigationTitle(Text("Enter a new item"))
}
}
}
}
Upvotes: 0
Views: 637