-1

I want to use UITextChecker to find the wrong word. Unfortunately, my code does not work as I expected. Can anyone correct my mistake, please? Here is my code. https://i.stack.imgur.com/4Ib8e.png

Thanks for helping me.

Dscyre Scotti
  • 1,307
  • 10
  • 17

2 Answers2

1

your code working properly

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

    return mispelledRange.location == NSNotFound
}

print(isCorrect(word: "apple"))
print(isCorrect(word: "ppale"))

enter image description here

Dilan
  • 2,610
  • 7
  • 23
  • 33
0

Here you can find the example for UITextChecker

Consider the example below:

func isReal(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
}

isReal(word: "apple") //true
isReal(word: "pple")  //false
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
  • 1
    I ran the code you mentioned above but it does not work like you. I think this error is due to my Xcode version. My current version is Version 11.4 beta (11N111s). Thanks bro. – Dscyre Scotti Mar 26 '20 at 06:00