How it works
AutomaticTextEditorStyle is the default text editor style that SwiftUI applies to a TextEditor when you don't request a specific appearance. It defers the editor's look and behavior to the system, so the field adopts whatever presentation is conventional for the current platform, context, and OS version. Reach for it when you want a TextEditor to feel native by default, or when you need to explicitly reset an editor back to standard styling after a custom style was applied higher in the view hierarchy.
Apply the style with textEditorStyle(.automatic)
You rarely construct
AutomaticTextEditorStyledirectly; instead you select it through thetextEditorStyle(_:)modifier using the.automaticshorthand. In the example,TextEditor(text: $note)receives.textEditorStyle(.automatic), which tells SwiftUI to use the system-chosen presentation rather than a custom one.Reach it through the TextEditorStyle protocol
AutomaticTextEditorStyleconforms to theTextEditorStyleprotocol, and.automaticis the static member that resolves to an instance of it. Because the modifier is generic overTextEditorStyle, writing.automaticis interchangeable with any other conforming style you might swap in later, keeping the call site onTextEditor(text: $note)uniform.Bind the editor's text independently of the style
The style controls appearance and behavior only; the content still flows through the editor's text binding. Here
@State private var noteis passed as$notetoTextEditor(text:), andAutomaticTextEditorStyleleaves that two-way binding untouched while governing how the editor draws.Compose layout modifiers around the styled editor
Styling does not preclude ordinary layout configuration:
AutomaticTextEditorStylecooperates with the modifiers chained after it. In the example,.frame(height: 140)and.border(.secondary)size and outline the sameTextEditor, while the automatic style determines the editor's intrinsic text presentation inside that frame.
.textEditorStyle(.automatic) to .textEditorStyle(.plain) and watch whether the editor's default decoration shifts, which reveals what the automatic, system-chosen styling was contributing.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct AutomaticTextEditorStyleDemo: View {
@State private var note = "Meeting notes:\n- Ship preview\n- Review PR"
var body: some View {
VStack(alignment: .leading) {
Text("Notes").font(.headline)
TextEditor(text: $note)
.textEditorStyle(.automatic)
.frame(height: 140)
.border(.secondary)
}
.padding()
}
}