Swift and SwiftUI call graph for AI agents
callgraph parses .swift files with
tree-sitter-swift and shows your agent types,
methods and computed properties with line ranges, property wrappers, and every call by category — with SwiftUI
views and modifiers as their own categories.
What callgraph extracts from Swift
- Containers:
class,struct,enum,protocol,actorandextension; nested types asOuter.Inner. - A type conforming to
Viewis acomponent— a SwiftUI view, like a Vue component. - File-level functions and statements go into a
<File>.swiftmodulecontainer. - Methods:
func,init,deinit,subscriptand computed properties, sovar body: some View { … }is the methodbodywith return typesome View. - Properties with their property wrapper before the type:
@State String,@StateObject TodoViewModel,@Published [Todo]. - Constants (
static let, file-levellet) and enum cases. - Branches of
if,switchandguard(--format flow), string literals with interpolations, doc comments.
A file that contains import SwiftUI is marked as SwiftUI.
SwiftUI-aware call categories
| Category | When |
|---|---|
swiftui_view | a built-in SwiftUI view: Text, VStack, HStack, List, NavigationStack, Button… |
swiftui_modifier | a known modifier: padding, font, onAppear, navigationTitle, sheet, toolbar… |
component_use | your own View type used in a view body, e.g. TodoRow(...) |
swiftui_api | withAnimation, withTransaction |
native_swift | stdlib, Foundation, Dispatch, Combine: UUID(), JSONDecoder().decode, DispatchQueue.main.async, append, map… |
internal_helper | a function defined in the same file, or self.f() |
instantiation | other type constructors |
external_call | other member calls, e.g. viewModel.load() |
Commands
CG=~/.claude/skills/callgraph/callgraph.sh
bash $CG --project myapp <path/to/View>.swift # outline: types, body, properties with wrappers, calls
bash $CG --project myapp <path/to/View>.swift::body --body # just the view body, line-numbered
bash $CG --project myapp <path/to/View>.swift --format flow # if / switch / guard branches with line ranges
Who calls this Swift method?
bash $CG --project myapp <folder> --grep '(^|::|\.|->)load$' # every call of the name
bash $CG --project myapp <folder> --grep '(^|::|\.|->)load$' --depth 2
Swift has no cross-file type resolution in callgraph, so search by name: the name pattern finds every call of
load, whatever the receiver.
Limits
- No type resolution and no cross-file symbol table: categories come from the names in the file and known lists.
A view declared in another file counts as
instantiationoutside a view body. - The stdlib method list is by name: your own
filterorappendis alsonative_swift. #ifbranches are all walked; macros such as#Previewand@Observableare not expanded.