swiftuilive-previewxcode12

Unable to enter text in TextField when using live previews in Xcode 12 (beta)


I appreciate that Xcode 12 is in its first beta state but this seems (on initial glance) to be a fairly major bug so I'm wondering if I've missed something...

The issue is with TextField when viewing it in a live Preview. Although the view is interactive (scrolling vertically seems to be OK within Forms and Lists) and a cursor appears in the TextField view when it is touched, keyboard input is ignored. (this is a

The same code works as expected in Xcode 11.5. Simulator in both 11.5 and 12 exhibits expected behaviour.

Is this a bug? I am running Catalina (10.15.5) so perhaps there's a compatibility issue and the issue would resolve with Big Sur? I know there is an issue with interactivity in Preview with multiple views inside PreviewProvider but I'd assumed this is if you'd added multiple Views to the same body of this struct.

The code below replicates the problem:

import SwiftUI

struct ContentView: View {
    @State private var text = ""

    var body: some View {
        Form {
            TextField("Enter text here", text: $text)
          }
    }
}

Solution

  • Quick response from a Frameworks engineer:

    Howdy,

    I'm sorry to hear you are having problems with interactive previews. As you've noticed, there is a currently known issue with keyboard input during an interactive preview session. We are working on a fix to this.

    Sims works fine so I'll use this for now. It's funny how quickly you get used to a new way of doing things (Previews) and experience significant pain when you have to rely on what you used for years without complaining!