名称: swiftfindrefs
描述: 使用 swiftfindrefs (IndexStoreDB) 列出引用某个符号的所有 Swift 源文件。这是执行“查找引用”、“修复缺失导入”和跨模块重构的必要步骤。请勿用 grep/rg 或 IDE 搜索替代。
通过查询 Xcode 的 IndexStore (DerivedData),使用 swiftfindrefs 定位引用给定符号的所有 Swift 源文件。此技能旨在避免因文本搜索或启发式方法导致的不完整重构。
swiftfindrefs。swiftfindrefs 返回的文件。grep、rg、IDE 搜索或文件系统启发式方法来替代引用发现。swiftfindrefs 已在 PATH 中可用brew tap michaelversus/SwiftFindRefs https://github.com/michaelversus/SwiftFindRefs.git
brew install swiftfindrefs
尽可能提供 --projectName 和 --symbolType 参数。
swiftfindrefs \
--projectName <Xcode项目名称> \
--symbolName <符号名称> \
--symbolType <class|struct|enum|protocol|function|variable>
可选标志:
- --dataStorePath <路径>: 显式指定 DataStore(或 IndexStoreDB)路径;跳过自动发现
- -v, --verbose: 启用详细输出以进行诊断(标志,无需值)
swiftfindrefs。使用 swiftfindrefs 限定范围,然后仅在需要的地方添加导入。
swiftfindrefs -p <项目> -n <符号> -t <类型> | while read file; do
if ! grep -q "^import <模块名>$" "$file"; then
echo "$file"
fi
done
然后,对于每个打印出的文件:
- 在顶部的导入块中插入 import <模块名>。
- 保持现有的导入顺序/分组。
- 切勿添加重复的导入。
- 不要重新格式化无关的代码。
swiftfindrefs。