Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Autocomplete in iOS

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.

like image 894
dsgriffin Avatar asked Feb 19 '13 15:02

dsgriffin


1 Answers

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.

like image 186
Eddy Borja Avatar answered Sep 27 '22 21:09

Eddy Borja