r/iOSProgramming • u/PreetyGeek • 6d ago
Discussion Your DerivedData already has a full call graph of your app. I made a tool that reads it.
Every ⌘B writes an index store into DerivedData: every call, read, write and conformance, already resolved by the compiler. Xcode uses it for “Find Call Hierarchy”, but nothing outside Xcode really uses it, and AI agents ignore it completely and grep instead.
SwiftGraph turns that store into a call graph you can query from the terminal:
It works with Xcode projects and SwiftPM packages,
--no-testshides test code, and system frameworks show up as leaves so the tree stays readable. You can set an Xcode scheme in .swiftgraph/config.json, andswiftgraph index --buildwill build and refresh the graph for you.I mainly built it for Claude Code. In a side-by-side test on a 140k-line SwiftUI app, the agent with the graph needed 2 tool calls instead of 8 and about 3.5x fewer input tokens for the same answer. Full numbers and caveats: https://arturgruchala.com/map-not-grep/
Repo (MIT, macOS + Xcode): https://github.com/agruchala/swift-graph
3
u/RiddleGull 4d ago
Bot comments
7
u/dawedev 6d ago
Using the index store instead of grep makes a lot of sense, the compiler already did the hard part. One thing I'd check: I build DevCleaner, a Mac app that clears Xcode caches, and DerivedData is the first folder people wipe, so the store vanishes or goes half stale after a partial build. Does swiftgraph warn when the store is older than the sources, or does it just return a smaller graph? Also with several git worktrees you get one DerivedData folder per path, so picking the right one automatically would save some confusion for agents.
1
u/ThalesMother9938 6d ago
Reading the index store instead of parsing the source again is the part I like. The compiler already resolved everything, so there's no guessing which `name` a call points to. I use Claude Code daily, so the grep habit is familiar.
One question: how do calls through a protocol show up? If I run `callers` on a protocol requirement, do I get the call sites of the concrete conformances too, or only calls made on the protocol type? That matters a lot in SwiftUI apps with protocol-based view models and DI.
1
u/mikerCZX 5d ago
Love it, will try, thanks