Reflection
Register the native iOS reflection tool suite to inspect explicitly registered roots and optionally call root-owned mutation or invocation adapters.
Install
Published pod: AnsightToolsReflection.
SwiftPM:
.product(name: "AnsightToolsReflection", package: "ansight-sdk")
CocoaPods:
pod 'AnsightToolsReflection', '1.0.2-preview.1'
Register the Suite
import AnsightCore
import AnsightToolsReflection
AnsightReflectionRootRegistry.register(
id: "session",
object: sessionViewModel,
displayName: "Current Session"
)
try AnsightRuntime.shared.registerReflectionTools()
Registration API
AnsightReflectionRootRegistry.register(...): exposes a live object root.AnsightReflectionRootRegistry.registerGetter(...): exposes a root through a getter.AnsightReflectionRootRegistry.deregister(...): removes one root.AnsightReflectionRootRegistry.clear(): removes all roots.registerReflectionTools(options:): registers the reflection suite.AnsightReflectionToolsOptions.createBuilder(): creates a suite options builder.allowRoot(...)/allowTypePrefix(...): narrows reflection traversal.
Specific Concerns
- Reflection can expose private state, model graphs, and user data.
- Register narrow roots instead of broad application objects.
reflect.set_member_valuerequires a root-ownedAnsightReflectionMutableRootpath.reflect.invoke_methodrequires a root-ownedAnsightReflectionInvokableRootpath.- Set and invoke are write-scoped.
Tool Matrix
| Name | Id | Scope | Description | Security |
|---|---|---|---|---|
List Reflection Roots | reflect.list_roots | Read | Lists registered reflection roots. | High |
Inspect Object | reflect.inspect_object | Read | Returns a snapshot of a registered root or nested path. | Critical |
Describe Type | reflect.describe_type | Read | Returns runtime type metadata. | Moderate |
Set Member Value | reflect.set_member_value | Write | Calls a root-owned AnsightReflectionMutableRoot setter path. | Critical |
Invoke Method | reflect.invoke_method | Write | Calls a root-owned AnsightReflectionInvokableRoot method. | Critical |
Tool Details
Use read tools to list roots, inspect object snapshots, and describe types. Enable write access only when your registered roots intentionally support mutation or invocation.
Root descriptors returned by reflect.list_roots include hostRuntime, which identifies the runtime that owns the root. iOS roots report kind: "swift" with the Swift/Objective-C runtime display name, so clients can route reflection commands to the native runtime boundary instead of inferring ownership from root ids or labels.