Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a better way to handle this dictionary search?
    primarykey
    data
    text
    <p>I'm creating an iPhone application. I have a .plist file that contains a dictionary of words (around 180K of them).</p> <p>There is a textField where the user begins typing a word. As he types, I use the delegate method <code>textField:shouldChangeCharactersInRange:replacementString:</code> to make sure that he only enters abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. </p> <p>When the user first taps in the textField, I load an NSMutableArray called <code>finalWords</code> (declared in the header, retained and synthesized) with the contents of the .plist (each word is an NSString). When the user enters a letter, I run this</p> <pre><code>-(void)filterWordsForString:(NSString *)string { NSRange *range; for (int i=[finalWords count]-1 ; i &gt;=0 ; i--) { range = [[finalWords objectAtIndex:i] rangeOfString:string]; if (range.location == NSNotFound) { [finalWords removeObjectAtIndex:i]; } } } </code></pre> <p>My goal is to stop the user whenever he enters a string that isn't part of a real word (according to my dictionary). This code works in the sense that it whittles down the possible words the user is typing as he goes. This way, as soon as he types a letter that makes it so he cannot complete it to a word, I don't allow the letter to be entered. Also, once there is a unique completion, I go ahead and fill the textField with the completed word. </p> <p>The problem is that this is painfully slow at first! It takes several seconds for the first letter, and not much less for the second. By the third, the speed is somewhat reasonable. Is there a way that I can drastically speed up this filtering process?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload