swift - Checking if a word is real -
i want make sure word real , code:
var checker: uitextchecker = uitextchecker() var range: nsrange = nsrange(location: 0,length: (count(completeword))) var misspelledrange: nsrange = checker.rangeofmisspelledwordinstring(completeword, range: range, startingat: 0, wrap: false, language: "en_us") var isrealword: bool = misspelledrange.location == nsnotfound if isrealword { println("correct") } else { println("not correct") }
but if give letter, says correct. can that? basically, want remove letters corrects.
uitextchecker gives misspelled words in sentence. won't show wrong letter in word, wrong word in whole text input.
for example:
var checker: uitextchecker = uitextchecker() let string:nsstring = "airplane gren" var range: nsrange = nsrange(location: 0,length: string.length) var misspelledrange: nsrange = checker.rangeofmisspelledwordinstring(string string, range: range, startingat: 0, wrap: false, language: "en_us") misspelledrange.torange()
gives result 12..<16, i.e whole word.
you use guessesforwordrange
possible correct substitutes:
let guesses = checker.guessesforwordrange(misspelledrange, instring: string string, language: "en_us") as? [string]
(returns ["green", "greg", "grep", "grew", "grey", "gran", "grin", "glen", "aren", "oren", "wren"]
)
Comments
Post a Comment