2

I have textfield has .editedChanged event. when user type "Boy" it will send : "B" send to API for search and waiting for responding.
"Bo" send to API for search and waiting for responding. "Boy" send to API for search and waiting for responding. The problem is , it will request 3 times to server and get 3 times of responding from server.

****How can i send only 1 time "Boy" send to API for search and waiting responding ??

Daniel
  • 355
  • 2
  • 3
  • 15

1 Answers1

2

An effective way to do this is to monitor how long of a delay there is between user input, and only request to the server after the user has stopped typing for x amount of time.

For instance, the user types 'B' and waits 0.05 seconds then types 'o' and waits 0.08 seconds then types 'y' and stops typing.

If your code only submits to the server after there has been at least 0.5 seconds between character input, it will only request to the server once, after "Boy" has been entered.

igoldthwaite
  • 289
  • 1
  • 8
  • Considering you didn't provide any code it would be hard for me to give an example. Granted, I do not do ios or swift development but I have dealt with a similar problem with c# user input in the past. – igoldthwaite Feb 08 '17 at 03:57
  • Actually, take a look at this http://stackoverflow.com/a/29763089/7531811 it might be the answer you're looking for, and would be more helpful than what I could tell you not having experience with swift! – igoldthwaite Feb 08 '17 at 04:02
  • now i am testing it. thanks i will let u know if it work – Daniel Feb 08 '17 at 04:12
  • Glad I could help! – igoldthwaite Feb 08 '17 at 04:36