Implement autocomplete in iOS

I am creating an application where I need to implement autocomplete when the user enters text input, with the 10 closest / highest ranking words appearing under the text box.

I was given a fairly large list of approximately 80,000 words and their corresponding "priority" - a number that determines how high they appear in autocomplete depending on the size of the number, for example:

"transport international";19205 "taxi";18462 "location de voitures";18160 "police";18126 "formation";17858 

I am new to iOS development and wondered how best to do this - should I split 80,000 phrases into smaller files or just save them in one? What will be faster?

I saw the autocomplete used in the example for iOS, but it was for a very small number of sentences - I did not see it done using the file that was so big before, and obviously I would like to do it as quickly as possible for additional user convenience.

Any suggestions regarding examples, tutorials or code suggestions would be greatly appreciated, thanks.

+6
source share
4 answers

You can use this HTAutocompleteTextField repo, the perfect solution.

+6
source

If you prefer what autocomplete does, but is a direct subclass of UITextField, then MLPAutoCompleteTextField may interest you.

MLPAutoCompleteTextField works by simply asking your autocomplete data source for an array of autocomplete suggestions every time the text in the text field changes. It can even automatically sort words so that those closest to what the user enters appear at the top of the autocomplete list (using the Levenshtein Distance algorithm). Autocomplete suggestions can be simple strings or objects that implement the MLPAutoCompletionObject protocol.

Tip. . For a large dataset of autocomplete terms, you probably want to split your list based on the initial letters. (Example: when the user enters the letter F, you provide the autocomplete text box with only a list of words starting with F.)

MLPAutoCompleteTextField can efficiently sort several thousand offers in a reasonable amount of time and will never block the user interface when sorting it.

Currently, weighted sentences (which override the default sorting) are not possible, but this is a planned feature.

+7
source

https://github.com/TarasRoshko/TRAutocompleteView

Just combine the TRAutocompleteItemsSource protocol and it. The protocol is designed with asynchronous support. The demo application and sample TRGoogleMapsAutocompleteItemsSource should help you with it.

+2
source

This link worked well for me. Depending on your code, just don't miss the difference between a UITextField and a UITextView .

No additional libraries, just a simple custom UITableView and search function.

0
source

All Articles