| name | add-identifiers |
| description | Apply accessibility identifier fixes from a doctor report to Swift source files. Adds .accessibilityIdentifier() modifiers to interactive elements. Use after /swift-assist:doctor. |
| argument-hint | [--report=<path>] [--dry-run] [--screen=<ViewName>] |
Swift Assist: Fix
Read the doctor report and apply .accessibilityIdentifier() modifiers to Swift source files for every interactive element that is missing one.
Usage
/swift-assist:add-identifiers
/swift-assist:add-identifiers --dry-run
/swift-assist:add-identifiers --screen=LoginView
/swift-assist:add-identifiers --report=.grantiva/doctor-report.json
Command Options
--report=<path>: Path to doctor report JSON (defaults to .grantiva/doctor-report.json)
--dry-run: Show what changes would be made without modifying files
--screen=<ViewName>: Only fix elements in a specific view
Prerequisites
A doctor report must exist. If .grantiva/doctor-report.json is not found:
No doctor report found. Run /swift-assist:doctor first to scan your app.
What This Command Does
Phase 1: Load Report
- Read the doctor report from
.grantiva/doctor-report.json (or --report path)
- Filter findings to only elements where
has_identifier is false
- If
--screen is specified, filter to only that view
- Group findings by file path
Phase 2: Apply Fixes
For each finding, edit the Swift source file to add .accessibilityIdentifier().
SwiftUI Element Patterns
Button:
Button("Continue") {
login()
}
Button("Continue") {
login()
}
.accessibilityIdentifier("login-button-continue")
TextField:
TextField("Email", text: $email)
TextField("Email", text: $email)
.accessibilityIdentifier("login-textfield-email")
SecureField:
SecureField("Password", text: $password)
SecureField("Password", text: $password)
.accessibilityIdentifier("login-securefield-password")
Toggle:
Toggle("Notifications", isOn: $notifications)
Toggle("Notifications", isOn: $notifications)
.accessibilityIdentifier("settings-toggle-notifications")
Image (interactive):
Image("hero-banner")
.resizable()
Image("hero-banner")
.resizable()
.accessibilityIdentifier("onboarding-image-hero-banner")
NavigationLink:
NavigationLink("Profile") {
ProfileView()
}
NavigationLink("Profile") {
ProfileView()
}
.accessibilityIdentifier("home-link-profile")
TabView tabs:
ProfileView()
.tabItem {
Label("Profile", systemImage: "person")
}
ProfileView()
.tabItem {
Label("Profile", systemImage: "person")
}
.accessibilityIdentifier("home-tab-profile")
Placement Rules
- Add
.accessibilityIdentifier() as the LAST modifier on the element, after all visual modifiers
- If the element already has accessibility modifiers (
.accessibilityLabel, .accessibilityHint), place the identifier after those
- Match the indentation style of the existing code (tabs vs spaces, indent level)
- Do NOT add identifiers to elements inside
ForEach unless they can be made unique (append index or data ID)
Phase 3: Verify Changes
After applying all fixes:
- Read each modified file to confirm the edits look correct
- Check that the code still compiles:
grantiva diff capture --no-build
Or if a full rebuild is needed, use grantiva diff capture (without --no-build).
- If build fails, immediately revert the last set of changes and report the error
Phase 4: Summary
Accessibility Fix Report
========================
Files modified: 6
Identifiers added: 23
LoginView.swift +5 identifiers
HomeView.swift +3 identifiers
SettingsView.swift +2 identifiers
ProfileView.swift +4 identifiers
OnboardingView.swift +6 identifiers
CheckoutView.swift +3 identifiers
Coverage: 47/47 elements now have identifiers (100%)
Next steps:
/swift-assist:make-tests - Generate test flows using these identifiers
/swift-assist:vrt - Set up visual regression baselines
If --dry-run was specified, show the same summary but prefix with "DRY RUN - no files were modified" and show the diffs that would be applied.
Important Rules
- NEVER change existing accessibility identifiers - only add missing ones
- NEVER modify any code logic - only add
.accessibilityIdentifier() modifier calls
- If a file has unsaved changes (check git status), warn the user before modifying
- Preserve exact whitespace and formatting of the existing code
- If the build fails after applying fixes, revert ALL changes to that file and report the error
- For
ForEach elements, skip them and note in the report: "Skipped: element inside ForEach requires unique ID strategy"