(NOTE: I have no problem getting UITextChecker to return completions of partially entered wods, ie where the range is not empty, but contains partially written word(prefixe)s, allthough the resulting completions are not sorted so that the more probable comes first, as the documentation says.
I have tried all day to find any other way to get next-word-of-sentence-predictions/-suggestions/-completions on iOS but failed. completionsForPartialWordRange (contrary to NSSpellChecker's) simply returns nil if the range has zero length. Run the iOS app and it will just print nil.
#Ios vietnamese keyboard predictive text code#
(this code can be put in the viewDidLoad of the ViewController of an otherwise empty Single View iOS app.) availableLanguages() says "en_US" on iOS and "en" on OS X. Print(UITextChecker.availableLanguages()) completionsForPartialWordRange an zero-length range located at the end of the string (where the next word would go), rather than a range containing a partial word, allthough I guess you could say that a non-existing word is also a partial word.)īut trying the same approach on iOS (using UITextChecker instead of NSSpellChecker, etc.) does not work: Note that the first three words are exactly the same as those displayed by the native (predictive) iOS keyboard. Running that program will print: Optional() Let completions = pletionsForPartialWordRange( Let spellChecker = NSSpellChecker.sharedSpellChecker() So here is a tiny command line app that does exactly what I want (allthough only on OS X): I want to make use of this next-word prediction logic on iOS, but it turns out that I can only get it to work on OS X, where it's super simple.
It will suggest three contextually relevant next-word-predictions on the bar at the top of the keyboard: On an iOS device, using the native keyboard (US english and "Predictive" turned on), if you write eg: