Function customDump(_:name:indent:maxDepth:)
@discardableResult
public func customDump<T>(
_ value: T,
name: String? = nil,
indent: Int = 0,
maxDepth: Int = .max
) -> T
Dumps the given value's contents using its mirror to standard output.
This function aims to dump the contents of a value into a nicely formatted, tree-like description. It works with any value passed to it, and tries a few things to turn the value into a string:
- If the value conforms to
CustomDumpStringConvertible
, then the string returned fromcustomDumpDescription
is used immediately. - If the value conforms to
CustomDumpRepresentable
, then the value it returns fromcustomDumpValue
is used for the dump instead. - If the value conforms to
CustomDumpReflectable
, the custom mirror returned fromcustomDumpMirror
is used for the dump instead. - Otherwise, the default mirror returned from
Mirror.init(reflecting:)
is used, which will either come from the type'sCustomReflectable
conformance, or from the default mirror representation of the value.
Parameters
Name | Type | Description |
---|---|---|
value | T |
The value to output to the |
name | String? |
A label to use when writing the contents of |
indent | Int |
The number of spaces to use as an indent for each line of the output. The default is |
maxDepth | Int |
The maximum depth to descend when writing the contents of a value that has nested components. The default is |
Returns
The instance passed as value
.