0Pricing
Swift Academy · Lesson

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)  // 2

All lessons in this course

  1. CustomStringConvertible
  2. CustomDebugStringConvertible
  3. Reflection with Mirror
  4. Building Debug-Friendly Types
← Back to Swift Academy