防止 Swift 中的单词自动更正

Prevent Autocorretion of a Word in Swift

只要在应用程序内的 UITextViews 中提及,我客户的聊天应用程序就会自动更正。 因此,如果每当用户在应用程序的 UITextView 中键入 XYZ 时将其称为 XYZ(只是编造的),它就会尝试自动更正它。

我知道这是 small/petty 的事情,但他觉得看到应用程序的名称试图为它的用户更改是很尴尬的,如果这有意义的话。

我有没有可能让实际应用程序中的 UITextView 忽略该特定词?或者这是否需要在每个用户的基础上修改用户的 SwiftKey 或其他东西来避免?

感谢任何人可以提供的任何帮助/指导!

您可以在根视图控制器的 viewDidLoad() 中使用 UITextChecker

UITextChecker.learnWord("xyz")

NSHipster blog 提供的关于 UITextChecker 的文档非常丰富的教程。

你应该关注博客的 Learning a New word 部分,它应该会给你答案

只是为了人们不想跳转链接

Let’s assume that you want your users to be able to type "xyz" exactly. Let your app know that by telling it to learn the word, using the UITextChecker.learnWord(_:) class method:

let someNewWordTheAppNeedsToLearn = "xyz"    
UITextChecker.learnWord(someNewWordTheAppNeedsToLearn)

我相信您可以创建一个包装器 class 专门用于让应用学习单词并在您的应用委托中调用它。

Apple Documentation