Search code examples
iosobjective-ckeyboardios-keyboard-extension

Keyboard extension no common words, no autocorrect


I've been working on a little keyboard extension, and now I've reached the fase of implementing autocorrect, or something that will show what the user could be attempting to write. The keyboard is just for myself, so just danish.

The documentation says that UILexicon contains some common words, which it doesn't. It contains my contacts, and not even that works. The only thing I get is like this: morten=morten, where it should be morten=Morten. They're all like this.

Then I tried the UITextChecker, and tried this in a playground (Swift, but the keyboard is in ObjectiveC: import UIKit var str:String = "h" var textChecker:UITextChecker = UITextChecker(); var range:NSRange = NSMakeRange(0, 1) var lan:NSArray = UITextChecker.availableLanguages() var t:String = lan[1] as String var ar:NSArray = textChecker.completionsForPartialWordRange(range, inString: str, language: t)!

This returns results in any language but da_DK, which is somewhat weird.

How should I do this? Should I download a danish dictionary and use it in the app using some kind of mysql database? Is my code somehow wrong, or is UILexicon simply broken for the danish language?


Solution

  • Try taking a look at the UITextChecker class.

    It's pretty strait forward to use:

    NSString * test = @"stavefej";
    
    NSArray * suggestions = [self.spellChecker guessesForWordRange:NSMakeRange(0, [test length]) inString:test language:@"da_DK"];  
    NSArray * autoCom = [self.spellChecker completionsForPartialWordRange:NSMakeRange(0, [test length])  inString:test language:@"da_DK"];