How do you use UILexicon in Objective-C? I find the documentation Apple provides is extremely unhelpful.
What does it do? Does it return a dictionary or proper spellings of words? Or do I provide a word like "hellllo" and it matches it with the proper spelling "Hello" and returns that as a string?
Any help would be appreciated.
requestSupplementaryLexiconWithCompletion:
Here's my error report, but obviously I'll have errors because I'm completely guessing how to use the function, no clue what goes inside the block statement (because the docs (at the time) don't say! (Beta 4 docs)) Hahahah!
I've never used this feature, but a quick web search for "UILexicon" landed me in Apple's documentation; reading and following links from there filled in the picture pretty quick.
App Extension Programming Guide has a quick explanation of what lexicons are for:
Clicking the
UILexicon
link on that page took me to the reference doc for that class, which explains that it's a read-only list of Apple-provided term pairs. Each of its entries is aUILexiconEntry
object -- the docs for that class say it provides auserInput
(what the user typed, e.g. "ipad") and adocumentText
(what to substitute for it, e.g. "iPad"). Since those classes are read-only, it follows that they're probably not a way for you to provide your own autocorrection pairs -- as stated in the docs, they're for supplementing whatever autocorrection system you implement.At this point, I don't even have to look at the doc for
requestSupplementaryLexiconWithCompletion:
to get a good idea how to use it: just the declaration tells me:UIInputViewController
, the class I'd have to subclass to create a custom keyboard. Somewhere in that subclass I should probably call it onself
.void
, so I can't get a lexicon by assigning the result of arequestSupplementaryLexiconWithCompletion
call to to a variable.UILexicon
object as a parameter to that block.So, I'm guessing that if I were writing a custom keyboard, I'd call this method early on (in
viewDidLoad
, perhaps) and stash theUILexicon
it provides so I can refer to it later when the user is typing. Something like this:Because it's unclear how long
requestSupplementaryLexiconWithCompletion
will take to complete, any place where I'm usingself.lexicon
I should check to see if it'snil
.Back in the App Extension Programming Guide, it lists "Autocorrection and suggestion" under "Keyboard Features That iOS Users Expect", right before saying:
So it sounds like autocorrection is something you have to do yourself, with your own UI that's part of the view presented by your
UIInputViewController
subclass. The API Quick Start for Custom Keyboards section in the programming guide seems to hint at how you'd do that: usedocumentContextBeforeInput
to see what the user has recently typed,deleteBackward
to get rid of it, andinsertText:
to insert a correction.