Skip to content
Discussion options

You must be logged in to vote

That's some standard issue with Textfield and you have the same issue in vanilla SwiftUI:

struct ContentView: View {
  @State var text: String = ""
  var body: some View {
    TextField(
      "",
      text: Binding(
        get: { text },
        set: {
          print("Set:", $0)
          self.text = text
        }
      )
    )
  }
}

In this configuration the binding's setter is activated twice for each key stroke. This is caused by the way UI/NSTextField are wrapped in SwiftUI, and I don't think there is much you can do prevent it.

You can probably mitigate the effect by debouncing the action. Other solutions that would count the actions would make you assume that this behavior is c…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ivangodfather
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
apple bug Something isn't working due to a bug on Apple's platforms.
3 participants