# Run Xcode Accessibility Audit on a Remote Mac

Canonical: https://figment.so/blog/mac-accessibility-audit-xcode-remote

Add a UI test that calls performAccessibilityAudit, then run it with xcodebuild test on a Mac with a compatible Xcode. Figment's Apple Silicon VM ($39 a month or $6 a day) runs current Xcode and the Simulator.

**Add a UI test that calls `XCUIApplication.performAccessibilityAudit(for:_:)`, then run it with `xcodebuild test` on any Mac that has a compatible Xcode and the iOS Simulator.** The API lives in the XCUIAutomation framework and is available from Xcode 16.3, iOS 17, macOS 14, tvOS 17 and watchOS 10 ([Apple: Performing accessibility audits for your app](https://developer.apple.com/documentation/accessibility/performing-accessibility-audits-for-your-app), [WWDC23 session 10035](https://developer.apple.com/videos/play/wwdc2023/10035/)).

If you rent the Mac from Figment, the Apple Silicon Mac VM ($39 a month, or $6 a day) runs current Xcode and the Simulator. The Intel Mac VM ($25 a month) runs macOS Sequoia, where Apple lists Xcode up to 26.3; that is enough for this API, but not for Xcode 26.4 or later, arm64-only binaries or visionOS. We have not measured audit speed on any plan, so time your own suite.

## What does the audit check?

`performAccessibilityAudit(for:_:)` walks every accessible element currently visible and returns one `XCUIAccessibilityAuditIssue` per problem Apple's auditor finds. It is the same set of checks Accessibility Inspector runs when you press its Audit button, exposed from code so CI can fail a pull request on a regression. You can scope the sweep to one or more `XCUIAccessibilityAuditType` values or pass `.all`.

| Audit type | What it flags |
|---|---|
| `.contrast` | Text with contrast below readable thresholds |
| `.dynamicType` | Text that does not scale with the user's preferred size |
| `.elementDetection` | Views the system cannot resolve as a single element |
| `.hitRegion` | Interactive elements the auditor judges too small to activate reliably |
| `.sufficientElementDescription` | Controls with missing or empty accessibility labels |
| `.textClipped` | Labels that truncate at larger accessibility text sizes |
| `.trait` | Missing or inconsistent accessibility traits |

Apple owns the exact thresholds (minimum hit-region size, contrast ratio) and may move them between OS versions. Treat the API's verdict as authoritative in CI; do not hard-code pixel or ratio numbers into your tests to try to pre-compute what it will say.

## Which UI test do I add?

Drop this into your UI-test target. Replace the screen-driving lines, the button label and the suppressed identifier with your own project's values because the audit is only as useful as the screens you walk it through.

```swift
import XCTest  // XCUIAutomation ships with XCTest UI-test targets.

final class AccessibilityAuditTests: XCTestCase {

    private let app = XCUIApplication()

    override func setUpWithError() throws {
        continueAfterFailure = true     // Collect every issue in one run.
        app.launchArguments = ["--ui-testing"]
        app.launch()
    }

    // A plain sweep: fails the test on any issue returned by the audit.
    func testLaunchScreenAudit() throws {
        try app.performAccessibilityAudit()  // defaults to .all
    }

    // A focused sweep with a narrowly typed suppression.
    func testOnboardingAudit() throws {
        app.buttons["Get started"].tap()

        try app.performAccessibilityAudit(for: .all) { issue in
            // Suppress one known finding: the decorative logo's contrast
            // rating, reviewed separately. Any other audit type on the
            // same element still fails the test.
            guard issue.auditType == .contrast,
                  let element = issue.element,
                  element.identifier == "decorative_app_logo"
            else {
                return false        // report as a test failure
            }
            return true             // ignore just this one finding
        }
    }
}
```

Three details to keep honest. First, the handler closure is the second *positional* parameter: there is no `handler:` label in Apple's signature. Second, `issue.element` is `XCUIElement?`, so unwrap before using it; the auditor can report an issue without a resolved element. Third, narrow suppressions by both `auditType` and element identifier; returning `true` for every finding on one element would silence every audit category against that element forever.

If you want a tight pre-submission tripwire rather than a full `.all` sweep, pass a focused option set:

```swift
try app.performAccessibilityAudit(for: [
    .contrast,
    .sufficientElementDescription,
    .hitRegion
])
```

## How do I run the audit on a remote Mac?

Connect to the Mac over SSH or remote desktop. CI agents (GitHub Actions self-hosted runners, Buildkite, Bitrise) connect outbound from the Mac to your pipeline. Install the Xcode version that matches the iOS versions your users run.

Once a runner is attached, the audit job is a plain `xcodebuild` invocation against your own workspace, scheme and simulator. The test target is the one you added above; everything else is a parameter you set from your project.

```bash
#!/usr/bin/env bash
set -euo pipefail

: "${WORKSPACE:?set to your .xcworkspace or .xcodeproj}"
: "${UI_TEST_SCHEME:?set to the scheme that contains AccessibilityAuditTests}"
: "${SIMULATOR:?example: platform=iOS Simulator,name=iPhone 16,OS=latest}"

xcodebuild test \
  -workspace "$WORKSPACE" \
  -scheme "$UI_TEST_SCHEME" \
  -destination "$SIMULATOR" \
  -only-testing:"$UI_TEST_SCHEME/AccessibilityAuditTests" \
  -resultBundlePath "./audit.xcresult"
```

Upload `audit.xcresult` as a CI artifact and inspect it with Xcode or `xcrun xcresulttool` when a failure needs triage. The result bundle carries screenshots of the elements the auditor flagged, which is faster than rerunning the suite to find out which button lost contrast. Do not grep stdout for "failed" and call it green: let `set -e` propagate the non-zero exit from `xcodebuild`.

For manual follow-up on a flagged screen, open a remote desktop session, launch **Xcode → Open Developer Tool → Accessibility Inspector**, point it at the running simulator and click Audit to walk the element tree by hand.

## How much does a year of audit runs cost?

Compare the hosts you would keep for a year. Figment's Apple Silicon VM is a virtual machine with shared vCPUs; CloudMac's listing is a whole Mac mini M4.

| Option | Monthly | 12-month cost |
|---|---|---|
| Figment Apple Silicon Mac VM (4 shared vCPUs, 4GB, 65GB) | $39 | $468 |
| Figment Dedicated M4 Pro 48 GB (M4 Pro, 48GB, 512GB), paid a year ahead | $269 | $3,228 |
| [CloudMac M4, 16GB, 256GB, monthly](https://cloudmac.org/pricing) | $99.99 | $1,199.88 |
| [CloudMac M4, 16GB, 256GB, paid a year ahead](https://cloudmac.org/) | $83.25 | $999.00 |

Arithmetic: 12 × $39 = $468; $3,228 ÷ 12 = $269; 12 × $99.99 = $1,199.88; $999 ÷ 12 = $83.25. If you only run the audit before a release, Figment's daily plan is cheaper still: four release days a month on the Apple Silicon VM cost 4 × $6 = $24. CloudMac's 256GB row read "Reserve now" when checked on November 10, 2026, so confirm availability before you prepay.

## How do I map a failure back to code?

Each audit type usually has a one-line fix. The UIKit column stays conservative on hit-region: the auditor measures the frame it can see, so grow the frame. `accessibilityActivationPoint` moves where VoiceOver taps the element, it does not enlarge the hit region. `.contentShape(Rectangle())` changes the shape that receives gestures within the view's bounds; it does not expand the layout, so use it together with a larger frame if the view is too small.

| Audit failure | SwiftUI fix | UIKit fix |
|---|---|---|
| `.sufficientElementDescription` | `.accessibilityLabel("Buy ticket")` | `view.accessibilityLabel = "Buy ticket"` |
| `.hitRegion` | enlarge the tappable view, e.g. `.frame(minWidth: 44, minHeight: 44)` | enlarge the view's frame or add a transparent hit view sized up to the target |
| `.contrast` | adjust foreground/background colour tokens | adjust `UIColor` assets and dark-mode variants |
| `.trait` | `.accessibilityAddTraits(.isButton)` | `view.accessibilityTraits.insert(.button)` |
| `.dynamicType` | `.font(.body)` and other scalable text styles | `UIFontMetrics.default.scaledFont(for:)` |
| `.textClipped` | allow multiline or set `.minimumScaleFactor` | enable multiline / shrink-to-fit on the label |

Run the audit on every pull request and review each suppression in code review. That shifts the noisy accessibility work off reviewers and before the submission build, even though it cannot catch every regression: the API only inspects visible elements on the screens your tests walk through. Compare the [Mac hosting plans](/mac-hosting) to pick the machine that runs it.

**Related guides:**
- [Test watchOS Apps Using a Remote Mac Simulator](/blog/mac-watchos-simulator-remote-mac)
- [Build a Multiplatform Xcode Project Remotely](/blog/mac-multiplatform-xcode-project)
- [Mac GitHub Actions Self-Hosted Runner](/blog/mac-github-actions-self-hosted-runner)
