Initializerswift 6.0.1Swift
init(_:children:displayStyle:ancestorRepresentation:)
Creates a mirror representing the given subject with a specified structure.
init<Subject, C>(_ subject: Subject, children: C, displayStyle: Mirror.DisplayStyle? = nil, ancestorRepresentation: Mirror.AncestorRepresentation = .generated) where C : Collection, C.Element == (label: String?, value: Any)
Parameters
- subject
The instance to represent in the new mirror.
- children
The structure to use for the mirror. The collection traversal modeled by
children
is captured so that the resulting mirror’s children may be upgraded to a bidirectional or random access collection later. See thechildren
property for details.- displayStyle
The preferred display style for the mirror when presented in the debugger or in a playground. The default is
nil
.- ancestorRepresentation
The means of generating the subject’s ancestor representation.
ancestorRepresentation
is ignored ifsubject
is not a class instance. The default is.generated
.
You use this initializer from within your type’s customMirror
implementation to create a customized mirror.
If subject
is a class instance, ancestorRepresentation
determines whether ancestor classes will be represented and whether their customMirror
implementations will be used. By default, the customMirror
implementation of any ancestors is ignored. To prevent bypassing customized ancestors, pass .customized({ super.customMirror })
as the ancestorRepresentation
parameter when implementing your type’s customMirror
property.
Other members in extension
Types
enum AncestorRepresentation
The representation to use for ancestor classes.
enum DisplayStyle
A suggestion of how a mirror’s subject is to be interpreted.
Typealiases
typealias Child
An element of the reflected instance’s structure.
typealias Children
The type used to represent substructure.
Type members
init<Subject>(Subject, children: KeyValuePairs<String, Any>, displayStyle: Mirror.DisplayStyle?, ancestorRepresentation: Mirror.AncestorRepresentation
) Creates a mirror representing the given subject using a dictionary literal for the structure.
init<Subject, C>(Subject, unlabeledChildren: C, displayStyle: Mirror.DisplayStyle?, ancestorRepresentation: Mirror.AncestorRepresentation
) Creates a mirror representing the given subject with unlabeled children.
init(reflecting: Any
) Creates a mirror that reflects on the given instance.
Instance members
let children: Mirror.Children
A collection of
Child
elements describing the structure of the reflected subject.var customMirror: Mirror
var description: String
let displayStyle: Mirror.DisplayStyle?
A suggested display style for the reflected subject.
let subjectType: any Any.Type
The static type of the subject being reflected.
var superclassMirror: Mirror?
A mirror of the subject’s superclass, if one exists.
func descendant(any MirrorPath, any MirrorPath...
) -> Any? Returns a specific descendant of the reflected subject, or
nil
if no such descendant exists.