TechnologiesSwiftUIAccessibility

AccessibilityActionKind struct

iOSmacOStvOSwatchOSvisionOSiOS 13.0+✓ renders

The structure that defines the kinds of available accessibility actions.

How it works

AccessibilityActionKind is a structure that identifies which kind of action an accessibility action represents, letting assistive technologies like VoiceOver invoke the right behavior on a view. Rather than passing free-form strings, you name a well-known interaction — the primary activation, the magic tap, escape, or a custom named action — through one of the type's predefined values. Reach for it whenever you attach an accessibilityAction(_:_:) modifier and need to declare what semantic gesture should run your closure, so that users who navigate by gesture or switch control can trigger the same outcomes a sighted user gets by tapping.

  1. Identify the action with a predefined kind

    Each AccessibilityActionKind value maps to a standard assistive gesture, so the system knows when to fire your handler. The example uses two of them: .default, the primary activation that VoiceOver triggers with a double-tap, and .magicTap, the two-finger double-tap reserved for a screen's most important action.

  2. Pass the kind to accessibilityAction(_:_:)

    You don't construct AccessibilityActionKind directly in normal use; you hand one of its values to accessibilityAction(_:_:) as the first argument, followed by the closure to run. In the example, .accessibilityAction(.default) increments count, while .accessibilityAction(.magicTap) resets it to zero.

  3. Stack multiple kinds on one element

    Because each kind is distinct, you can apply several accessibilityAction modifiers to the same view and each binds its own closure to a different AccessibilityActionKind. Here .default and .magicTap coexist on the same VStack, giving that one element two separately addressable behaviors.

  4. Make the actions land on a single accessible element

    An action kind attaches to the accessibility element it modifies, so the surrounding view should be exposed as one element. The example calls .accessibilityElement(children: .combine) first, merging the two Text views into a single element that then owns both the .default and .magicTap actions.

Try it — Change the .magicTap closure from count = 0 to count -= 1, then perform a two-finger double-tap under VoiceOver to confirm the magic-tap kind runs that handler independently of the default activation.

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.

AccessibilityActionKind.swift
struct AccessibilityActionKindDemo: View {
    @State private var count = 0
    var body: some View {
        VStack(spacing: 12) {
            Text("Taps: \(count)")
                .font(.headline)
            Text("Use VoiceOver: activate or magic-tap me")
                .multilineTextAlignment(.center)
        }
        .padding()
        .accessibilityElement(children: .combine)
        .accessibilityAction(.default) {
            count += 1
        }
        .accessibilityAction(.magicTap) {
            count = 0
        }
    }
}
Live preview
Taps: 0 Use VoiceOver: activate or magic-tap me
Taps: 0 Use VoiceOver: activate or magic-tap me
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →