iOS & macOS DevelopmentDocumentedScanned
swiftfindrefs
Use swiftfindrefs (IndexStoreDB) to list every Swift source file referencing a symbol.
Share:
Installation
npx clawhub@latest install swiftfindrefsView the full skill documentation and source below.
Documentation
SwiftFindRefs
Purpose
Useswiftfindrefs to locate every Swift source file that references a given symbol by querying Xcode’s IndexStore (DerivedData). This skill exists to prevent incomplete refactors caused by text search or heuristics.
Rules
- Always run
swiftfindrefsbefore editing any files. - Only edit files returned by
swiftfindrefs. - Do not substitute
grep,rg, IDE search, or filesystem heuristics for reference discovery. - Do not expand the file set manually.
- If IndexStore/DerivedData resolution fails, stop and report the error. Do not guess.
Preconditions
- macOS with Xcode installed
- Project has been built at least once (DerivedData exists)
swiftfindrefsavailable in PATH
Installation
brew tap michaelversus/SwiftFindRefs
brew install swiftfindrefs
Canonical command
Prefer providing--projectName and --symbolType when possible.
swiftfindrefs \
--projectName <XcodeProjectName> \
--symbolName <SymbolName> \
--symbolType <class|struct|enum|protocol|function|variable>
Optional flags:
--dataStorePath: explicit DataStore (or IndexStoreDB) path; skips discovery-v, --verbose: enables verbose output for diagnostic purposes (flag, no value required)
Output contract
- One absolute file path per line
- Deduplicated
- Script-friendly (safe to pipe line-by-line)
- Ordering is not semantically meaningful
Standard workflows
Workflow A: Find all references
swiftfindrefs for the symbol.Workflow B: Fix missing imports after moving a symbol
Useswiftfindrefs to restrict scope, then add imports only where needed.
swiftfindrefs -p <Project> -n <Symbol> -t <Type> | while read file; do
if ! grep -q "^import <ModuleName>$" "$file"; then
echo "$file"
fi
done
Then for each printed file:
- Insert
importin the imports block at the top. - Preserve existing import ordering/grouping.
- Never add duplicate imports.
- Do not reformat unrelated code.
Workflow C: Audit usage before deleting or renaming a symbol
swiftfindrefs for the symbol.References
- CLI details: references/cli.md
- Playbooks: references/workflows.md
- Troubleshooting: references/troubleshooting.md