6

I am creating an application where I need to implement autocompletion when a user is typing into an text input, with the 10 nearest/highest ranking words appearing below the text field.

I've been given a fairly big list of around 80,000 words and their respective 'priority' - a number which determines how high up they appear in the autocomplete depending on the size of the number, like this:

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

I am kinda new to iOS development and was wondering what is the best way to do this - should I split the 80,000 phrases into smaller files, or just keep it in one? What would be faster?

I have seen autocompletion used in an example for iOS but it was for a very small amount of suggestions - I haven't seen it done using a file this large before, and obviously I would like to make it as fast as possible for added user experience.

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

dsgriffin
  • 66,495
  • 17
  • 137
  • 137

4 Answers4

7

If you prefer something that does autocomplete but is a direct subclass of UITextField, then MLPAutoCompleteTextField may be of interest to you.

MLPAutoCompleteTextField works by simply asking its autocomplete datasource for an array of autocomplete suggestions each time the text in the textfield changes. It can even automatically sort words so that the ones closest to what the user is typing will appear at the top of the autocomplete list (using a Levenshtein Distance algorithm). Autocomplete suggestions can be simple strings, or objects that implement MLPAutoCompletionObject protocol.

Tip: For a large dataset of autocomplete terms, you'll probably want to break up your list based on starting letters. (Example: When the user enters the letter F, you give the autocomplete textfield only a list of words that start with F.)

MLPAutoCompleteTextField can efficiently sort several thousand suggestions in a reasonable amount of time, and will never block the UI while it sorts.

At the moment, weighted suggestions (that override the default sorting) aren't possible but it's a planned feature.

Eddy Borja
  • 1,638
  • 17
  • 21
6

You may want to use this repo HTAutocompleteTextField, perfect solution.

Ben Lu
  • 2,982
  • 4
  • 31
  • 54
  • 2
    @user1394965 [This repo](https://github.com/EddyBorja/MLPAutoCompleteTextField) may be what you want. – Ben Lu Feb 20 '13 at 20:10
  • 1
    Try my PJTernarySearchTree as the data source for HTAutocompleteTextField: https://github.com/peakji/PJTernarySearchTree – PeakJi Mar 06 '13 at 14:10
2

https://github.com/TarasRoshko/TRAutocompleteView

Just conform TRAutocompleteItemsSource protocol and that's it. Protocol is designed with async support in mind. Demo app and sample TRGoogleMapsAutocompleteItemsSource should greatly help you with it.

illegal-immigrant
  • 8,089
  • 9
  • 51
  • 84
0

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

No extra libraries, just an easy custom UITableView and search function.

craned
  • 2,991
  • 2
  • 34
  • 38