Mirror - leacode/SwiftWings GitHub Wiki
Source: Sources/Extensions/Foundation/Mirror/Mirror+Reflection.swift
Tests: Tests/Extensions/Mirror
- Iterates over
Mirror(reflecting: target).childrenand 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.
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