-2

在 Swift 4 中使用 UITextChecker 时出现错误。以下代码很可能适用于 Swift 3,我只是不确定 Swift 4 中的问题是什么?这是我的代码:

import UIKit
var correctStr : String = String()
let str = "Helo"
let textChecker = UITextChecker()
let misspelledRange = textChecker.rangeOfMisspelledWordInString(
            str, range: NSRange(0..<str.utf16.count),
            startingAt: 0, wrap: false, language: "en_US")

        if misspelledRange.location != NSNotFound,
            let guesses = textChecker.guessesForWordRange(
                misspelledRange, inString: str, language: "en_US") as? [String]
        {
            correctStr = guesses.first

        }

我收到这个错误:“使用未解析的标识符'UITextChecker'。

您的帮助将不胜感激。

4

1 回答 1

2

API已重命名,您的代码应为rangeOfMisspelledWordInStringguessesForWordRange

import UIKit
var correctStr : String = String()
let str = "Helo"
let textChecker = UITextChecker()

let misspelledRange = textChecker.rangeOfMisspelledWord(in: str, range: NSRange(0..<str.utf16.count), startingAt: 0, wrap: false, language: "en_US")
if misspelledRange.location != NSNotFound,
  let guesses = textChecker.guesses(forWordRange: misspelledRange, in: str, language: "en_US") {
  correctStr = guesses.first!
}
于 2017-10-20T22:17:31.823 回答