objective c - IOS Custom Keyboard Suggestions with UITextChecker -
here reached far. have function receive string , showing me suggestions custom keyboard.
-(void)suggestionsforcustomkeyboard:(nsstring *)word{
nsarray *arrpredectivetext; uitextchecker *checker = [[uitextchecker alloc] init]; nslocale *currentlocale = [nslocale currentlocale]; nsstring *currentlanguage = [currentlocale objectforkey:nslocalelanguagecode]; nsrange searchrange = nsmakerange(0, word.length); arrpredectivetext = [checker completionsforpartialwordrange:searchrange instring:word language:currentlanguage]; nsarray *guesses = [nsarray array]; if ([currentstring length] >= 1) { uitextchecker *textchecker = [[uitextchecker alloc] init]; nsrange misspelledrange = [textchecker rangeofmisspelledwordinstring:currentstring range:nsmakerange(0, [currentstring length]) startingat:0 wrap:no language:@"en_us"]; if (misspelledrange.location != nsnotfound) { guesses = [textchecker guessesforwordrange:misspelledrange instring:currentstring language:@"en_us"]; nslog(@"first guess: %@", [guesses firstobject]); } else { nslog(@"textchecker not found"); autocorrectedtext = @""; } if (arrpredectivetext.count >= 2){ suggestionone = [arrpredectivetext objectatindex:0]; suggestiontwo = [arrpredectivetext objectatindex:1]; } else if (arrpredectivetext.count == 1 && guesses.count >= 1) { suggestionone = [arrpredectivetext firstobject]; suggestiontwo = [guesses firstobject]; }else if (arrpredectivetext.count == 0 && guesses.count > 0){ suggestionone = [guesses firstobject]; if (guesses.count > 1) { suggestiontwo = [guesses objectatindex:1]; } } nslog(@"textchecker guess: %@", guesses); nslog(@"prediction: %@",arrpredectivetext); }
the last 2 lines print statement 2 types. 1 guesses words when misspelled occurred , other dictionary words. arrpredectivetext array contains words sequentially dictionary.
please give idea or way solving suggestion , next word predict mechanism ios custom keyboard other apps. or suggestion appreciated.
Comments
Post a Comment