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_value requires a root-owned AnsightReflectionMutableRoot path.
  • reflect.invoke_method requires a root-owned AnsightReflectionInvokableRoot path.
  • Set and invoke are write-scoped.

Tool Matrix

NameIdScopeDescriptionSecurity
List Reflection Rootsreflect.list_rootsReadLists registered reflection roots.High
Inspect Objectreflect.inspect_objectReadReturns a snapshot of a registered root or nested path.Critical
Describe Typereflect.describe_typeReadReturns runtime type metadata.Moderate
Set Member Valuereflect.set_member_valueWriteCalls a root-owned AnsightReflectionMutableRoot setter path.Critical
Invoke Methodreflect.invoke_methodWriteCalls 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.