How it works
PlainTextEditorStyle is the text-editor style that renders a TextEditor as unadorned, plain text — no automatic rich-text affordances, just the characters the user types. It conforms to TextEditorStyle, the protocol SwiftUI uses to describe how an editor presents and edits its content, and you almost never name the type directly: you select it through the .plain static accessor on the textEditorStyle(_:) modifier. Reach for it when you want a lightweight, code-like or note-taking editing surface whose appearance you control yourself, rather than one that styles content for you.
Adopt the style with textEditorStyle(.plain)
Every TextEditor renders with an active editor style, and the textEditorStyle(_:) modifier is how you choose it. Applying
.textEditorStyle(.plain)to theTextEditor(text: $notes)resolves to a PlainTextEditorStyle value and tells SwiftUI to draw the editor as flat, unstyled text.Resolve PlainTextEditorStyle through the .plain accessor
PlainTextEditorStyle is exposed as a static member named
plainon TextEditorStyle, so the leading-dot.plainin the example is shorthand for the concrete style value. You rarely writePlainTextEditorStyle()by hand — the accessor keeps the call site readable while still conforming to the TextEditorStyle protocol the modifier expects.Bind editable content with TextEditor(text:)
The style only governs presentation; the editable text still flows through a binding. Here
TextEditor(text: $notes)is driven by the@State private var notesstring, and PlainTextEditorStyle leaves that text untouched — multi-line content like the newline-separated notes is shown verbatim.Control the surrounding chrome yourself
Because the plain style adds no decoration of its own, you supply any framing or sizing through ordinary modifiers. The
.frame(height: 140)and.border(Color.gray.opacity(0.4))after the style give the otherwise bare editor its bounds and outline — the style stays focused on the text, and you own the rest.
.textEditorStyle(.plain) line and rerun to compare the bare PlainTextEditorStyle against the platform's default editor appearance.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 PlainTextEditorStyleDemo: View {
@State private var notes = "Meeting notes:\n- Ship the preview\n- Review PR"
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text("Notes")
.font(.headline)
TextEditor(text: $notes)
.textEditorStyle(.plain)
.frame(height: 140)
.border(Color.gray.opacity(0.4))
}
.padding()
}
}