Search code examples
textfieldswiftui

Is it possible to turn off predictive text for a TextField?


I would like to turn off predictive text/autocorrect for a TextField in SwiftUI. Looks like this was possible with UITextField: Disable UITextField Predictive Text

I checked the Apple documentation for TextField and googled, but can't find anything about this.

Has anyone found a way to disable the predictive text/autocomplete for a TextField?


Solution

  • Seems like it is now possible using Xcode 11 Beta 5. There is a new modifier to disable the autocorrection on TextField

    func disableAutocorrection(_ disable: Bool?) -> some View
    

    https://developer.apple.com/documentation/swiftui/textfield/3367734-disableautocorrection?changes=latest_beta

    Edit: Modifier disableAutocorrection is deprecated in iOS 16.1. The new modifier is autocorrectionDisabled:

    func autocorrectionDisabled(_ disable: Bool = true) -> some View
    

    https://developer.apple.com/documentation/swiftui/presentedwindowcontent/autocorrectiondisabled(_:)?changes=latest_beta&language=_5