0

Below is test code I wrote in a Swift Playground. It shows UITextChecker is not working reliably.

   import UIKit

func validWord(word: String) -> Bool {
    let checker = UITextChecker()
    let range = NSRange(location: 0, length: word.utf16.count)
    let misspelledRange = checker.rangeOfMisspelledWord(in: word, range: range, startingAt: 0, wrap: false, language: "en")
    
    return misspelledRange.location == NSNotFound
}

for char in "abcdefghijklmnopqrstuvwxyz" {
    let word = String(repeating: char, count: 5)
    print("\(word): \(validWord(word: word) ? "Valid" : "Misspelled")")
    print("\(word.uppercased()): \(validWord(word: word.uppercased()) ? "Valid" : "Misspelled")")
}

Here are the results: aaaaa: Misspelled AAAAA: Valid bbbbb: Misspelled BBBBB: Valid ccccc: Valid CCCCC: Valid ddddd: Valid DDDDD: Valid eeeee: Misspelled EEEEE: Valid fffff: Misspelled FFFFF: Valid ggggg: Misspelled GGGGG: Valid hhhhh: Misspelled HHHHH: Valid iiiii: Valid IIIII: Valid jjjjj: Misspelled JJJJJ: Valid kkkkk: Misspelled KKKKK: Valid lllll: Valid LLLLL: Valid mmmmm: Valid MMMMM: Valid nnnnn: Misspelled NNNNN: Valid ooooo: Misspelled OOOOO: Valid ppppp: Misspelled PPPPP: Valid qqqqq: Misspelled QQQQQ: Valid rrrrr: Misspelled RRRRR: Valid sssss: Misspelled SSSSS: Valid ttttt: Misspelled TTTTT: Valid uuuuu: Misspelled UUUUU: Valid vvvvv: Valid VVVVV: Valid wwwww: Valid WWWWW: Valid xxxxx: Valid XXXXX: Valid yyyyy: Misspelled YYYYY: Valid zzzzz: Misspelled ZZZZZ: Valid

I would expect consistent results over the entire alphabet.

Richard Goggin
  • 331
  • 2
  • 4
  • 2
    Words in all uppercase are assumed to be valid initials and i, v, x, l, c, d, and m are all roman numerals so they are valid in a series while lowercase. Can't tell by your formatting if there are any outside of those that are appearing valid, but if there are, it's more likely actually a valid series of characters rather than not working correctly. – clawesome May 04 '22 at 20:23
  • Thanks for the prompt reply. Makes perfect sense. – Richard Goggin May 06 '22 at 16:57

0 Answers0