Using UILexicon to implement auto-correction in iOS 8 Keyboard extension

I saw that this question was asked several times, but no one seemed to answer. I am trying to create an auto-correction feature on a user keyboard, but I completely lost it on how to do this. Apple gives some documentation, but not very detailed. I know that this has something to do with UILexicon data, but I'm not sure what to do with it and how to use it to correct lines of text that the user enters.

Any help would be greatly appreciated.

What I have found so far:

let controller = UIInputViewController() controller.requestSupplementaryLexiconWithCompletion({ lexicon in println(lexicon.description) }) 

But that’s all I got. Not sure what to do next.

+8
ios8 swift ios8-extension
source share
1 answer

You are asking a very difficult question. In short, there is no native access to autocorrect on iOS8; there is also no access to iOS APIs that allow the system to do things such as a brief “possible error” effect or other aspects of the system’s auto-correction behavior, such as an in-place offer dialog box (on iOS 7, or if you don’t have a visible panel suggestions) or “fix” the blue background (on iOS 8).

things you cannot do:

dotted red line

error indicator in place

in-place suggestion

silent installation dialog

will correct

bardata auto-correction indicator

what you can do is write your own autocorrect mechanism from scratch, including both your own word processing and analysis, and your own user interface idioms. This should be done with a restriction that you cannot make outside the boundaries of your keyboard, and you cannot change anything else on the screen. A number of third-party keyboards do this, such as minuum and swiftkey (disclaimer: I work on a mini), but this is not an accidental amount of work. If you're interested in playing around with this, the built-in UITextChecker class may be a good place to start, although autocorrection is ultimately a problem other than spell checking.

UILexicon is useful only after you have already implemented things; all that he really offers you is a list of words that you can use to complement any dictionary that you use, as well as to implement any text shortcuts that your user could add to their system settings. This alone is not enough to create an automatic correction system.

Appendix: How to write a spelling corrector is a great little essay / tutorial by Peter Norwig that may seem interesting to you, and what I would recommend, do not try to write autocorrectly.

+9
source share

All Articles