Embed Autocorrect in iOS 8 Keyboard Extension

I am creating a regular iOS 8 keyboard as a pet project.

I try to reproduce the system keyboard as accurately as possible, but build it from scratch.

I basically do it. The last hurdle that I am facing is adding auto-correct to my keyboard. Is there a way in which autocorrect can behave like on a regular system keyboard?

UILexicon documentation is pretty rare.

EDIT:

Making some progress. UILexicon requestSupplementaryLexiconWithCompletion: method seems to only return results from my device. Contacts and keyboard shortcuts. Then I continued to browse the NSString AutoCorrect and found the UITextChecker class that was available with iOS 3.2.

Using this approach, I can autosave sentences for individual words, but I'm still exploring the possibility of adding context-sensitive autocorrection (for example, correcting “Arctic monkeys” to “Arctic monkeys”).

+5
source share
2 answers

From the documentation, it seems that UILexicon will help you create your own auto- UILexicon , UILexicon has a bunch of UILexiconEntry entries containing String strings, the record contains the userInput string, which I assume it is supposed to be the user entered, and documentText , which I assume is the one what you should replace with this input. You use func requestSupplementaryLexiconWithCompletion(_ completionHandler: ((UILexicon!) -> Void)!) From the UIInputViewController to get this UILexicon.

I assume that the UIInputViewController knows what was written in documentProxy, since it is a relay of these messages, and this is how it knows what the user is typing, and instead of typing in UILexicon ..

This is what I collected by reading the documentation, I did not test it, although it is not worth checking.

I hope this helps

Daniel

+1
source

Check out this simple but highly effective automatic correct implementation of http://norvig.com/spell-correct.html

For automatic completion, you can implement trie.

0
source

Source: https://habr.com/ru/post/1201451/


All Articles