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.
Identify the action with a predefined kind
Each
AccessibilityActionKindvalue 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.Pass the kind to accessibilityAction(_:_:)
You don't construct
AccessibilityActionKinddirectly in normal use; you hand one of its values toaccessibilityAction(_:_:)as the first argument, followed by the closure to run. In the example,.accessibilityAction(.default)incrementscount, while.accessibilityAction(.magicTap)resets it to zero.Stack multiple kinds on one element
Because each kind is distinct, you can apply several
accessibilityActionmodifiers to the same view and each binds its own closure to a differentAccessibilityActionKind. Here.defaultand.magicTapcoexist on the sameVStack, giving that one element two separately addressable behaviors.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 twoTextviews into a single element that then owns both the.defaultand.magicTapactions.
.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.
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
}
}
}