Mirror - leacode/SwiftWings GitHub Wiki

Mirror Extensions

Source: Sources/Extensions/Foundation/Mirror/Mirror+Reflection.swift

Tests: Tests/Extensions/Mirror

Mirror.reflectProperties

  • Iterates over Mirror(reflecting: target).children and invokes a closure for every child matching a given type.
  • Optionally recurses into nested properties when recursively == true.
  • Simplifies inspection/reflection logic without having to hand-roll mirror traversals.

Example

struct Person { let name: String; let age: Int }
let person = Person(name: "Rio", age: 30)

Mirror.reflectProperties(of: person, matchingType: String.self) { value in
  print("Found string:", value)
}
// Output: Found string: Rio
⚠️ **GitHub.com Fallback** ⚠️