0

The app to reproduce the problem is simple. It has 2 TextField. The button is just there to print out the value but the problem happens without it too. Run the app in the simulator, select the first text field, enter Bb, select the second text field, Bb becomes Vv in the first field. It happens for me using the hardware keyboard or the keyboard on in the emulator. If I use the hardware keyboard I get 2 messages about failing to fetch the device property, but if I use the emulator keyboard the only thing that is displayed is my print. I entered Dd in the first field, pressed the button, Dd stays in the fiend and prints, then I press the second TextField the Dd changes to Did, press the button again it prints Did. I took the preview out and still no joy. I got this by building a new app, replacing the hello world with the two TextField, the button, and the 2 @state variables. It might depend on having the same 2 characters in the TextField Bb becomes Vv but Do stays as Do. I try stuff by ending the app and starting it over. If you enter Dd it changes to Did and then if you go back to the first field and enter Dd again it stays. I rebooted the system. It's fun to try and guess what it will change to, Tt becomes Ty and Oo becomes Ok. If you use the hardware keyboard and press a key before selecting the field you get the two error messages, then select the field and enter Dd and you get no additional messages. OK, let's make it a bit stranger, I ran my tests emulating an iPhone12 but when I change the emulator to a iPad Pro 9.7 inch Dd becomes did, lower case d on the pad and upper on the phone. the iPad Air also goes to did. Here is the code

import SwiftUI
struct ContentView: View {
  @State private var nameX = ""
  @State private var displayName = ""
  var body: some View {
    VStack{
      TextField("Player Name", text: $nameX)
      TextField("Player Display Name", text: $displayName)
      Button ("save") {
        print (nameX)
      }
    }
  }
}
2
  • Voting to close as non-reproducible. What you're describing sounds like ordinary autocorrect; you can turn it off you like. Commented Aug 22, 2022 at 19:54
  • I searched any way I could think of for this problem. I completely forgot about autocorrect. Thank you. Also, thank you for editing out my snark. Commented Aug 22, 2022 at 20:10

1 Answer 1

1

It was autocorrect. I added

.disableAutocorrection(true)

to the TextField and the problem went away.

  TextField("Player Name", text: $nameX)
    .disableAutocorrection(true)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.