Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UILexicon to implement autocorrect in iOS 8 Keyboard Extension

I've seen that this question has been asked a few times, but no one seems to have an answer. I am trying to create an autocorrect feature on a custom keyboard, but I am completely lost as to how to do so. Apple gives some documentation, but it's not very detailed. I know it has something to do with UILexicon data, but I'm not sure what to do with it and how to use it to correct strings of text the user is typing.

Any help would be greatly appreciated.

What I have found so far:

let controller = UIInputViewController()

    controller.requestSupplementaryLexiconWithCompletion({
        lexicon in

        println(lexicon.description)

    })

But this is as far as I've gotten. Not sure what to do from here.

like image 635
SomeGuy Avatar asked Oct 05 '14 11:10

SomeGuy


People also ask

How do I make a custom keyboard for IOS?

Navigate to Settings > General > Keyboard > Keyboards > Add New Keyboard and select AC Custom Keyboard. This will add it to the list of available keyboards. Go back to your app and bring up the keyboard by tapping the text view. Tap and hold the globe key and select AC Keyboard from the list that pops up.

How do I add a language to my Iphone keyboard?

Add or remove a keyboard for another languageGo to Settings > General > Keyboard. Tap Keyboards, then do any of the following: Add a keyboard: Tap Add New Keyboard, then choose a keyboard from the list. Repeat to add more keyboards.


1 Answers

You are asking a very difficult question. In short, there is no built in access to autocorrect on iOS8; there is also no access to the APIs on iOS that allow the system to do things like show the red 'possible error' underline effect, or to other aspects of the system autocorrect behaviour, such as the in-place suggestion dialog (on iOS 7, or if you do not have the suggestions bar visible) or the 'will correct' blue background (on iOS 8).

things you can't do:

dotted red line

in-place error indicator

in-place suggestion

in-place autocorrect dialog

will correct

suggestions bar autocorrect indicator

what you can do is write your own autocorrect engine, from scratch, including both your own text processing and analysis and your own user-interface idioms. This has to all be done with the limitation that you are not able to draw outside of your keyboard's bounds, and you cannot modify anything else on screen. A number of third-party keyboards do this, such as minuum and swiftkey (disclaimer: I work on minuum) but it is a non-incidental amount of work. If you're interested in playing around with this, a good place to start might be the built in UITextChecker class, although auto-correction is ultimately a problem distinct from spell-checking.

UILexicon is only useful once you've already implemented things; all that it really offers you is a list of words that you can use to supplement whatever dictionary you're using, as well as to implement any text shortcuts your user might have added in their system settings. It is not, on its own, enough to build an auto-correction system from.

addendum: How to Write a Spelling Corrector is a great little essay / tutorial by Peter Norvig that you might find interesting, and that I would recommend even if you're not trying to write auto-correct.

like image 163
cmyr Avatar answered Sep 28 '22 03:09

cmyr