Search code examples
xcodetextfieldswiftuibeta

How to use RoundedBorderTextFieldStyle in SwiftUI for TextField after API change in Xcode 11 Beta 5?


Before Xcode 11 Beta 5. I used this syntax to put a rounded border outside my TextField:

TextField("Expression", text: $expression)
      .textFieldStyle(.roundedBorder)

Sadly, this approach is deprecated and gives me warning now.

The new approach should be: roundedBorder' is deprecated: Use RoundedBorderTextFieldStyle directly instead.

But I can't figure out a way to use it.

As I can tell from the developer documentation. RoundedBorderTextFieldStyle conforms to protocol TextFieldStyle.

And TextField seems to have RoundedBorderTextFieldStyle as nested struct?(Not sure if I understanding correctly, RoundedBorderTextFieldStyle is written below TextField in the developer documentation)

I can't figure out how to use the new RoundedBorderTextFieldStyle.

I'm looking for the correct way to write the code below in Beta 5:

    TextField("Placeholder", text: $texts)
        .textFieldStyle(.roundedBorder)

Solution

  • You say:

     .textFieldStyle(RoundedBorderTextFieldStyle())