init(_:children:displayStyle:ancestorRepresentation:)
Creates a mirror representing the given subject using a dictionary literal for the structure.
Declaration
init<Subject>(_ subject: Subject, children: KeyValuePairs<String, Any>, displayStyle: Mirror.DisplayStyle? = nil, ancestorRepresentation: Mirror.AncestorRepresentation = .generated)Parameters
- subject:
The instance to represent in the new mirror.
- children:
A dictionary literal to use as the structure for the mirror. The
childrencollection of the resulting mirror may be upgraded to a random access collection later. See thechildrenproperty 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.
ancestorRepresentationis ignored ifsubjectis not a class instance. The default is.generated.
Discussion
You use this initializer from within your type’s customMirror implementation to create a customized mirror. Pass a dictionary literal with string keys as children. Although an actual dictionary is arbitrarily-ordered, when you create a mirror with a dictionary literal, the ordering of the mirror’s children will exactly match that of the literal you pass.
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.