TechnologiesSwiftUI

TextInputDictationActivation struct

iOSmacOStvOSwatchOSvisionOS✓ renders

How it works

TextInputDictationActivation describes how dictation begins for a text-entry view, letting you choose whether voice input starts only on an explicit gesture or automatically when the person directs their attention to the field. SwiftUI normally requires a tap on the microphone control to start dictation; this type lets you opt into hands-free activation modes such as look-to-dictate, which is especially valuable on platforms where gaze or attention is a primary input. Reach for it when you want a TextField to accept spoken input more fluidly, without forcing the user to first tap a control.

  1. Apply the .textInputDictationActivation(_:) modifier

    You attach a dictation-activation policy to any text-entry view through the textInputDictationActivation(_:) modifier, which takes a TextInputDictationActivation value. In the example the modifier is applied directly to the TextField bound to $note, so that field adopts the chosen activation behavior.

  2. Pass an activation mode value

    TextInputDictationActivation is supplied as a value describing when dictation should engage. The example passes .onLookToDictate, which tells SwiftUI to begin dictation when the person looks at the field rather than requiring a separate microphone tap.

  3. Scope it to the field that receives the speech

    The activation policy only governs the view it modifies, so place it on the specific entry control whose input you want to drive by voice. Here it sits on the TextField (the one prompting "Tap mic or look to dictate") and not on the surrounding Text labels, keeping voice input targeted at where note is edited.

  4. Read the dictated result from the bound state

    Because the modifier changes only how dictation starts, the spoken text still flows into the same binding the field already uses. The @State property note updates as dictation fills the TextField, and the lower Text reflects it by showing note (or "Nothing yet" while empty).

Try it — Change .onLookToDictate in the textInputDictationActivation modifier to the default tap-driven activation and notice that dictation no longer starts from gaze alone, requiring an explicit microphone tap instead.

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.

TextInputDictationActivation.swift
struct TextInputDictationActivationDemo: View {
    @State private var note = ""
    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Text("Voice Note")
                .font(.headline)
            TextField("Tap mic or look to dictate", text: $note)
                .textFieldStyle(.roundedBorder)
                .textInputDictationActivation(.onLookToDictate)
            Text(note.isEmpty ? "Nothing yet" : note)
                .foregroundStyle(.secondary)
        }
        .padding()
    }
}
Live preview
Voice Note Tap mic or look to dictate Nothing yet
Voice Note Tap mic or look to dictate Nothing yet
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →