Antonon Stack Overflow • Recommends
On “SwiftUI: How to only run code when the user stops typing in a TextField?”
There's a fantastic PropertyWrapper solution to this by link to this video that lets you simply replace
@State var text = ""
with
@DebouncedState var text = ""
and you're done.
You can also set the amount of debouncing (which defaults to 0.3 seconds, or whatever you like). For a longer delay of 1.5 seconds: @DebouncedState(delay: 1.5) var text = ""
Here's his video: link to this video
And his code: https://gist.github.com/CodeSlicing/026d8481dea0e4f5f5da85ea4dce6fc4