Autocorrection is a built-in iOS mechanism that automatically corrects spelling errors when entering text. UIKit manages autocorrection behavior through the autocorrectionType property in the UITextInputTraits protocol, supporting three modes: default, enabled and disabled. According to Apple Text Programming Guide (2025), autocorrection analyzes input text based on the system dictionary and on-device machine learning. Use autocorrectionType for each text field individually — this allows adapting behavior to the specifics of the input data.
Key Takeaways
Autocorrection is an iOS operating system feature that automatically replaces typed words with presumably correct alternatives when a spelling error is detected. The mechanism works at the level of UIKit text fields and is available in all applications that use standard UITextField and UITextView input elements.
At the core of autocorrection is a language model trained on millions of text examples for each supported language. The model runs entirely on-device, ensuring the confidentiality of input data — text is not sent to Apple servers for analysis. With each iOS update, the model is refined and expanded with new words and rules.
Autocorrection is activated automatically for all text fields unless the developer explicitly disables it. The user can completely disable autocorrection in system settings (Settings > General > Keyboard > Auto-Correction), but the developer can also control this behavior for individual fields through the autocorrectionType property.
According to WWDC 2023 Session 204, Apple introduced an improved autocorrection language model based on Transformer, which considers the context of the entire sentence rather than just the last word. This reduced false corrections by 30% compared to the previous n-gram based model.
UITextAutocorrectionType is an enumeration with three values that determine autocorrection behavior for a specific text field. Each value is set via the autocorrectionType property, accessible in Interface Builder and in code when creating the field.
The .default value means the field inherits the global autocorrection setting from the system keyboard parameters. This mode is recommended for most text fields as it respects user choice. If the user has disabled autocorrection in settings, a field with .default will also not use it.
The .yes value forcibly enables autocorrection for the field regardless of the system setting. This mode should only be used for fields where spelling accuracy is critical — for example, in text editors, note input fields, or messages. Apple recommends using .yes with caution, as forced enabling may contradict user expectations.
The .no value disables autocorrection for a specific field. This mode is mandatory for password fields (secure text entry), email addresses, verification codes, and search queries. In these fields, autocorrection is not only useless but harmful — it can replace correctly entered data with erroneous alternatives.
| Mode | Value | Recommendation |
|---|---|---|
| .default | Inherits system setting | Most input fields |
| .yes | Forcibly enabled | Text editors, notes |
| .no | Forcibly disabled | Passwords, email, search, codes |
The language model of iOS autocorrection uses a combination of a static dictionary and a dynamically trained model. The system dictionary contains the most commonly used words for each language, while the Transformer-based language model analyzes context and replacement probability. The model trains on-device based on user-entered texts.
Users can add words to a personal dictionary through keyboard settings (Settings > General > Keyboard > Text Replacement). Added words are saved to iCloud and synced across devices using the same Apple ID. The system will not correct words from the personal dictionary, which is convenient for names, brands, and technical terms.
For specialized domains — medical, legal, technical — the standard dictionary may contain insufficient terms. In such applications, it is recommended to either disable autocorrection for relevant fields or use custom text replacement via the UIResponder method .replacementDictionary for iOS 17+.
According to Apple Machine Learning Research (2024), the new autocorrection model based on Transformer architecture processes up to 10 context tokens (compared to 3 tokens in the previous model), allowing more accurate determination of user intent. The model considers not only spelling but also the grammatical structure of the sentence.
Safe Keyboard is a protected input mode that automatically activates for fields with secureTextEntry = true. In this mode, autocorrection, autocapitalization, and predictive input are disabled by the system regardless of the set autocorrectionType values. The system also blocks access to the user dictionary and text replacements.
Safe Keyboard prevents leakage of input data through autocorrection mechanisms. If autocorrection were active for a password field, the system could save the entered password to the user dictionary or send it to Apple servers for model training. Safe Keyboard ensures that confidential data does not leave the application.
For financial applications, Safe Keyboard activates automatically only for fields with secureTextEntry. For card number, expiration date, and CVV code input fields, the developer must additionally disable autocorrection manually by setting autocorrectionType = .no and keyboardType = .numberPad or .phonePad.
Starting with iOS 17, Safe Keyboard supports interception protection against third-party keyboards. If the user has installed a keyboard from the App Store, when secureTextEntry is activated, the system keyboard automatically replaces the third-party one, even if it was selected as default. This ensures that passwords are entered only through the secure system keyboard.
Managing autocorrection in Swift is done through the autocorrectionType property of UITextField and UITextView objects. The property is available for both reading and writing, and can be changed dynamically depending on the input context. Configuration via Interface Builder is available in the attributes inspector under the name Correction.
let textField = UITextField()
textField.autocorrectionType = .no
For a login form, autocorrection should be disabled for the password field and enabled by default for the login field. The email field is also recommended to be left without autocorrection, as the @ symbol and domain names are often replaced incorrectly. For the username field, autocorrection can be enabled if the username is a readable word.
class RegistrationViewController: UIViewController {
@IBOutlet var nameField: UITextField!
@IBOutlet var emailField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
nameField.autocorrectionType = .yes
emailField.autocorrectionType = .no
emailField.textContentType = .emailAddress
}
}
For UITextView, autocorrection configuration is done similarly. This is especially important for multiline input fields for comments, messages, and notes, where autocorrection brings the most benefit but can also create inconvenience when entering technical terms or code.
let textView = UITextView()
textView.autocorrectionType = .default
For dynamic changes to autocorrection, use the UITextFieldDelegate protocol. The textFieldDidBeginEditing method is called when a field is activated, and in it you can change autocorrectionType depending on the current context or the role of the field, which may change during application operation.
Autocorrection should be disabled in fields where the accuracy of input data is critical and the system cannot correctly determine the user's intent. Main cases: password and secure data fields, email address input fields, search strings, code and program code input fields, as well as fields with non-standard data formats.
For search bars (UISearchBar), autocorrection is disabled by default, which matches user expectations. When searching, the user may enter incomplete words, technical terms, or queries in different languages, and autocorrection would only get in the way. Similarly for URL and domain name input fields.
In messengers and communication apps, autocorrection is usually enabled, but for entering slang, abbreviations, and informal vocabulary, it can create inconvenience. In such cases, the user can disable autocorrection through keyboard settings, or the developer can provide a toggle directly in the application interface.
According to Apple Human Interface Guidelines, autocorrection should be disabled for any field where the input data may not be found in the system dictionary: order numbers, booking codes, identifiers, IMEI, MAC addresses. If the field accepts alphanumeric data in a non-standard format — disable autocorrection.
Frequently Asked Questions
There is no global autocorrection disable for the entire application. You need to set autocorrectionType = .no for each text field individually or create a UITextField subclass with an overridden value.
The simulator uses a simplified input model from the Mac keyboard. The autocorrection language model is not active on the simulator — use a real device for testing.
The user can add a word through Settings > General > Keyboard > Text Replacement. There is no API for the application to programmatically add words to the system autocorrection dictionary.
No, keyboardType does not affect autocorrection. Even for the .numberPad keyboard, autocorrection can be active if not explicitly disabled via autocorrectionType.
Third-party keyboards have their own autocorrection mechanisms and do not use the system UITextAutocorrectionType. The behavior depends on the implementation of the specific keyboard.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also