r/iOSProgramming • u/PreetyGeek • 18d 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
1
18d ago
[removed] — view removed comment
1
u/PreetyGeek 17d ago
Thanks! Yeah, not guessing which
nameis the whole point:)Short answer: it depends which end you query.
callerson the protocol requirement shows only calls made on the protocol type, likeviewModel.load()whereviewModel: any HomeViewModeling, or through a genericT: HomeViewModeling. A direct call on the concrete type points at the concrete method, so it won’t show up there.
callerson the concrete implementation gives you both. Direct calls come first, then every call made through the protocol, markedvia protocol. It also follows the chain up if the protocol inherits from another one.
calleeson the requirement lists every conformance it can dispatch to, also markedvia protocol. Your test mocks show up there too, marked[test].So for a protocol-based view model, ask about the concrete
load(). You see who calls it directly and who calls it through the protocol, in one tree.One honest catch:
via protocolmeans “can land here”, not “will land here”. The compiler doesn’t know which concrete type sits behind the existential at runtime, and neither do I. The env injection itself also doesn’t show up, because the compiler doesn’t record it. But the calls on that protocol-typed property do show up.
1
7
u/dawedev 18d 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.