How nalexn/viewinspector works
ViewInspector is a Swift library for unit-testing SwiftUI views by reflecting on their runtime structure. A test starts inspection on a view, then traverses or searches the resulting hierarchy, reads view and modifier state, and can invoke supported callbacks to simulate interactions. The graph highlights the shared reflection and hierarchy machinery plus representative view, modifier, and popup inspection. README capabilities guide the coverage; several subsystem details are inferred from the file tree because their source was not sampled.
Main entry points: InspectableView.swift Inspectable hierarchy · ViewSearch.swift Find and traverse · Text.swift Text inspection · ContentExtraction.swift Content extraction
Components 18
Inspection entry
- Inspect entry
Sources/ViewInspector/InspectableView.swift - Inspection context
Sources/ViewInspector/ViewHosting.swift - Content extraction
Sources/ViewInspector/ContentExtraction.swift - Reflection utilities
Sources/ViewInspector/Inspector.swift
Hierarchy and search
- Inspectable hierarchy
Sources/ViewInspector/InspectableView.swift - Find and traverse
Sources/ViewInspector/ViewSearch.swift - View type index
Sources/ViewInspector/ViewSearchIndex.swift - Child collections
Sources/ViewInspector/LazyGroup.swift
View inspection
- Text inspection
Sources/ViewInspector/SwiftUI/Text.swift - SwiftUI view adapters
Sources/ViewInspector/SwiftUI/AnyView.swift - Modifier inspection
Sources/ViewInspector/Modifiers - Text attributes
Sources/ViewInspector/SwiftUI/TextAttributes.swift - Environment injection
Sources/ViewInspector/EnvironmentInjection.swift - Popup inspection
Sources/ViewInspector/SwiftUI/Alert.swift
State and interaction
- Gesture callbacks
Sources/ViewInspector/SwiftUI/Gesture.swift - Accessibility actions
Sources/ViewInspector/Modifiers/AccessibilityModifiers.swift
Other components
- Test author
- SwiftUI view under test
Connections 21
- Test author → SwiftUI view under test: provides view
- Test author → Inspect entry: starts inspection
- Inspect entry → Inspection context: creates context
- Inspect entry → Content extraction: unwraps view
- Content extraction → Reflection utilities: reflects structure
- Inspect entry → Inspectable hierarchy: creates root
- Inspectable hierarchy → Reflection utilities: reads attributes
- Inspectable hierarchy → Find and traverse: supports search
- Find and traverse → View type index: identifies types
- Find and traverse → Child collections: traverses children
- Inspectable hierarchy → SwiftUI view adapters: adapts view types
- Inspectable hierarchy → Text inspection: reads text
- Text inspection → Text attributes: reads attributes
- Inspectable hierarchy → Modifier inspection: reads modifiers
- Inspectable hierarchy → Environment injection: reads environment
- Inspectable hierarchy → Popup inspection: inspects popup
- Inspectable hierarchy → Gesture callbacks: invokes callbacks
- Inspectable hierarchy → Accessibility actions: invokes actions
- Test author → Find and traverse: finds views
- Test author → Text inspection: asserts text
- Test author → Gesture callbacks: simulates gesture