SpaceShroomies
SpaceShroomies

Reputation: 1635

Disablic spell check while keeping autocorrect in swift

In my UITextView when a user spells something incorrectly, it gets underlined in red. How can I remove this without disabling autocorrect?

Upvotes: 1

Views: 1974

Answers (2)

Gangireddy Rami Reddy
Gangireddy Rami Reddy

Reputation: 989

You can call this function where ever you wanted to check the spelling THen use bellow code

     func wordIsSpelledCorrect(_ word: String) -> Bool {
    let checker = UITextChecker()
    let range = NSMakeRange(0, word.characters.count)
    let wordRange = checker.rangeOfMisspelledWord(in: word, range: range, startingAt: 0, wrap: false, language: "en")
    return wordRange.location == NSNotFound



}

Use in this way

        if wordIsSpelledCorrect((yourTextField.text)!){

}

Upvotes: -1

simons
simons

Reputation: 2400

Text views have properties for both autocorrection and spelling checking. These can be set in the Attributes inspector. Or in code via spellCheckingType and autocorrectionType. In your case you would want to disable spell checking whilst leaving autocorrect enabled.

The various possible constant values are detailed at: UITextInputTraits

Upvotes: 3

Related Questions