Home > Enterprise >  Disable autocorrect on an iOS 15 SwiftUI searchable search bar
Disable autocorrect on an iOS 15 SwiftUI searchable search bar

Time:10-22

I have a SwiftUI and Core Data app and have implemented the new iOS 15 search bar API.

.searchable(text: $searchText) // This is a modifier under my List view

However, the search bar has autocorrect, which unexpectedly changes the search when the view disappears or the user commits (it even happens if navigating to a detail view and back). Overall it is a poor user experience.

I cannot find anything in the Apple documentation for disabling autocorrect on this search bar (although it is easily done for a standard TextField with the .disableAutocorrect(true) modifier).

I used a Swift Package for iOS14 that provided a search bar (via UIViewRepresentable), but I would rather use first party APIs if possible, so my question relates specifically to the iOS 15 SwiftUI .searchable API.

CodePudding user response:

The auto correction of the search bar get disabled if you set disableAutocorrection(true) after .searchable(text: $searchText)

List {
    //
}
.searchable(text: $searchText)
.disableAutocorrection(true)
  • Related