TechnologiesSwiftUI

AutomaticTextEditorStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default text editor style, based on the text editor's context.

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.

  1. Apply the style with textEditorStyle(.automatic)

    You rarely construct AutomaticTextEditorStyle directly; instead you select it through the textEditorStyle(_:) modifier using the .automatic shorthand. In the example, TextEditor(text: $note) receives .textEditorStyle(.automatic), which tells SwiftUI to use the system-chosen presentation rather than a custom one.

  2. Reach it through the TextEditorStyle protocol

    AutomaticTextEditorStyle conforms to the TextEditorStyle protocol, and .automatic is the static member that resolves to an instance of it. Because the modifier is generic over TextEditorStyle, writing .automatic is interchangeable with any other conforming style you might swap in later, keeping the call site on TextEditor(text: $note) uniform.

  3. 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 note is passed as $note to TextEditor(text:), and AutomaticTextEditorStyle leaves that two-way binding untouched while governing how the editor draws.

  4. Compose layout modifiers around the styled editor

    Styling does not preclude ordinary layout configuration: AutomaticTextEditorStyle cooperates with the modifiers chained after it. In the example, .frame(height: 140) and .border(.secondary) size and outline the same TextEditor, while the automatic style determines the editor's intrinsic text presentation inside that frame.

Try it — Change .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.

AutomaticTextEditorStyle.swift
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()
    }
}
Live preview
Notes Meeting notes:\n- Ship preview\n- Review PR
Notes Meeting notes:\n- Ship preview\n- Review PR
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →