Reflection with Mirror
Inspect properties of any value at runtime.
What Is Mirror?
Mirror is Swift runtime reflection: it lets you inspect a value structure — its properties and their values — without knowing the concrete type at compile time.
Creating a Mirror
Pass any value to Mirror(reflecting:):
struct Point { let x: Int; let y: Int }
let m = Mirror(reflecting: Point(x: 1, y: 2))
print(m.children.count) // 2All lessons in this course
- CustomStringConvertible
- CustomDebugStringConvertible
- Reflection with Mirror
- Building Debug-Friendly Types