Swift 4 中的 UITextChecker

UITextChecker in Swift 4

我在 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'。

非常感谢您的帮助。

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!
}