I'm doing the following to disable all auto-filling in my macOS app:
Text("ID:")
TextField("", text: bindingCurrentID)
.disableAutocorrection(true)
But it doesn't do anything. If I start typing spaces into that text field (after the text that is already there) the OS automatically adds a period at the end.
How do I disable it? Or remove all typex of automatic completion and let only user-typed stuff into that field?
CodePudding user response:
.disableAutocorrection()
is deprecated. You should use .autocorrectionDisabled()
instead. See documentation here.
struct ContentView: View {
@State private var text: String = ""
var body: some View {
TextField("Email", text: $text)
.autocorrectionDisabled() // prevents automatic correction from the system.
}
}
CodePudding user response:
A possible approach:
TextField("", text: $input)
.autocorrectionDisabled(true)
.onChange(of: input) { _ in
input = input.replacingOccurrences(of: ".", with: " ")
}