TechnologiesSwiftUI

AccessibilityAdjustmentDirection enum

iOSmacOStvOSwatchOSvisionOSiOS 13.0+✓ renders

A directional indicator you use when making an accessibility adjustment.

How it works

AccessibilityAdjustmentDirection is the enumeration SwiftUI hands you to describe how an assistive technology user is asking to change an adjustable element's value. When VoiceOver focuses a control marked as adjustable, the user swipes up or down (or uses the rotor) to nudge its value, and the system reports each gesture to your code as one of this enum's directions. Reach for it whenever a view exposes a continuous or stepped value—a rating, a counter, a custom slider—that assistive users need to raise or lower without touching its visual controls.

  1. Read the direction passed to accessibilityAdjustableAction(_:)

    An adjustable element advertises itself with the accessibilityAdjustableAction modifier, whose closure receives a single AccessibilityAdjustmentDirection value each time the user performs an adjust gesture. In the example the closure parameter direction carries that value, so your handler runs once per swipe and decides how to mutate the underlying state—here the @State property rating.

  2. Branch on .increment and .decrement

    The enum's two primary cases tell you which way the user swiped: .increment for an upward (increase) gesture and .decrement for a downward (decrease) one. The example switches on direction and maps .increment to rating += 1 and .decrement to rating -= 1, clamping each to the 0...5 range so the value never escapes its bounds.

  3. Handle future directions with @unknown default

    Because AccessibilityAdjustmentDirection is a non-frozen enum, SwiftUI may introduce additional directions in later releases, so an exhaustive switch must include an @unknown default arm. The example's @unknown default: break keeps the code forward-compatible—unrecognized directions are simply ignored rather than causing a compile error or crash.

  4. Pair adjustments with an accessibilityValue

    The direction only describes the change; you are responsible for announcing the result. The view combines accessibilityValue("\(rating) out of 5") with the adjustable action so that, after each .increment or .decrement, VoiceOver speaks the new value. The accessibilityElement() and accessibilityLabel("Rating") modifiers establish the single focusable element that the gesture targets.

Try it — Add a case .increment: rating += 2 change—or swap the bodies of the .increment and .decrement arms—and listen with VoiceOver to hear how each swipe direction now moves rating differently.

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.

AccessibilityAdjustmentDirection.swift
struct AccessibilityAdjustmentDirectionDemo: View {
    @State private var rating = 3

    var body: some View {
        VStack(spacing: 12) {
            Text("Rating: \(rating)")
                .font(.title2)
            Text("Swipe up/down with VoiceOver to adjust")
                .font(.caption)
                .foregroundStyle(.secondary)
        }
        .accessibilityElement()
        .accessibilityLabel("Rating")
        .accessibilityValue("\(rating) out of 5")
        .accessibilityAdjustableAction { direction in
            switch direction {
            case .increment:
                if rating < 5 { rating += 1 }
            case .decrement:
                if rating > 0 { rating -= 1 }
            @unknown default:
                break
            }
        }
        .padding()
    }
}
Live preview
Rating: 3 Swipe up/down with VoiceOver to adjust
Rating: 3 Swipe up/down with VoiceOver to adjust
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →