Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 683 Bytes

2020-05-18_how-to-detect-live-changes-on-textfield-in-swiftui.md

File metadata and controls

32 lines (24 loc) · 683 Bytes
title createdAt
How to detect live changes on TextField in SwiftUI?
2020-05-18 18:29:41 UTC

How to detect live changes on TextField in SwiftUI?

struct ContentView: View {
    @State var location: String = ""

    var body: some View {
        let binding = Binding<String>(get: {
            self.location
        }, set: {
            self.location = $0
            // do whatever you want here
        })

        return VStack {
            Text("Current location: \(location)")
            TextField("Search Location", text: binding)
        }

    }
}

https://stackoverflow.com/questions/57875550/how-to-detect-live-changes-on-textfield-in-swiftui