5

I'm creating a custom iOS 8 keyboard as a pet project.

I'm trying to replicate the system keyboard as accurately as possible, but building it from the ground up.

I'm largely done with this. The final hurdle I'm encountering is with adding autocorrect to my keyboard. Is there a way I can have the autocorrect behave as it would on the regular system keyboard?

The UILexicon documentation is quite sparse.

EDIT:

Making some progress with this. UILexicon's requestSupplementaryLexiconWithCompletion: method appears to only be returning results from my device's Contacts and keyboard shortcuts. I then went on to see how to autocorrect an NSString and found the UITextChecker class, which has been available since iOS 3.2.

Using this approach I can achieve autocorrect suggestions on individual words, but I'm still investigating the ability to add context-aware autocorrect (e.g. correcting "arctic monkeys" to "Arctic Monkeys").

Andrew
  • 15,357
  • 6
  • 66
  • 101
Kiran Panesar
  • 3,094
  • 2
  • 22
  • 28

2 Answers2

1

From the documentation, it seems that UILexicon is to help you to create your own autocorrect, UILexicon has a bunch of UILexiconEntry entries which contain String pairs, the entry contains a userInput String which I assume its supposed to be what the user entered, and documentText which I assume is what you should be replacing that input with. You use func requestSupplementaryLexiconWithCompletion(_ completionHandler: ((UILexicon!) -> Void)!) From UIInputViewController to get this UILexicon.

I am assuming that the UIInputViewController knows what has been written to the documentProxy since it is the one relaying those messages, and thats how it knows what the user has input and in return what to put in the UILexicon..

This is what I gathered from reading the documentation, I have not tested it, though it should not be very hard to test this to verify..

I hope it helps

Daniel

Daniel
  • 22,363
  • 9
  • 64
  • 71
  • Yup, I spent some time looking into UILexicon and it appears to only be returning results from the user-defined shortcuts and Contacts. It's not pulling in any data from the default system dictionary. – Kiran Panesar Sep 02 '14 at 23:02
  • @KiranPanesar How would you go about setting up your own custom dictionary? I was thinking of creating an NSDictionary with key and value pairs, but is UILexicon better performance-wise? It feels like there's hardly any documentation or thorough examples. – KingPolygon Oct 02 '14 at 05:00
  • 1
    Method `requestSupplementaryLexiconWithCompletion:` always returns same array. It is NOT useful for autocorrect feature – Tony Oct 06 '14 at 02:49
0

Check out this simple but very effective auto correct implementation http://norvig.com/spell-correct.html

For auto completion you can implement a trie.

Jeet
  • 1,030
  • 2
  • 10
  • 20
  • Please include some information about why and how that helps. Also, please duplicate some of the information here in case the link dies. – xlecoustillier Apr 22 '15 at 14:38
  • 1
    Folks, you are heading down muddy waters here. This is NOT a simple task! – Randy Sep 23 '16 at 03:11