Structure

Mirror

A representation of the substructure and display style of an instance of any type.

Overview

A mirror describes the parts that make up a particular instance, such as the instance’s stored properties, collection or tuple elements, or its active enumeration case. Mirrors also provide a “display style” property that suggests how this mirror might be rendered.

Playgrounds and the debugger use the Mirror type to display representations of values of any type. For example, when you pass an instance to the dump(_:_:_:_:) function, a mirror is used to render that instance’s runtime contents.

struct Point {
    let x: Int, y: Int
}

let p = Point(x: 21, y: 30)
print(String(reflecting: p))
// Prints "▿ Point
//           - x: 21
//           - y: 30"

To customize the mirror representation of a custom type, add conformance to the CustomReflectable protocol.

Topics

Querying Descendants

func descendant(MirrorPath, MirrorPath...)

Returns a specific descendant of the reflected subject, or nil if no such descendant exists.

protocol MirrorPath

A protocol for legitimate arguments to Mirror’s descendant method.

Type Aliases

typealias Mirror.Child

An element of the reflected instance’s structure.

typealias Mirror.Children

The type used to represent substructure.

Initializers

Instance Properties

let children: Mirror.Children

A collection of Child elements describing the structure of the reflected subject.

let displayStyle: Mirror.DisplayStyle?

A suggested display style for the reflected subject.

let subjectType: Any.Type

The static type of the subject being reflected.

var superclassMirror: Mirror?

A mirror of the subject’s superclass, if one exists.

Enumerations

enum Mirror.AncestorRepresentation

The representation to use for ancestor classes.

enum Mirror.DisplayStyle

A suggestion of how a mirror’s subject is to be interpreted.

Relationships

See Also

Querying Runtime Values

struct ObjectIdentifier

A unique identifier for a class instance or metatype.

func type<T, Metatype>(of: T)

Returns the dynamic type of a value.

func == (Any.Type?, Any.Type?)

Returns a Boolean value indicating whether two types are identical.

func != (Any.Type?, Any.Type?)

Returns a Boolean value indicating whether two types are not identical.