CustomDump Documentation

Function custom​Dump(_:​name:​indent:​max​Depth:​)

@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:

  1. If the value conforms to CustomDumpStringConvertible, then the string returned from customDumpDescription is used immediately.
  2. If the value conforms to CustomDumpRepresentable, then the value it returns from customDumpValue is used for the dump instead.
  3. If the value conforms to CustomDumpReflectable, the custom mirror returned from customDumpMirror is used for the dump instead.
  4. Otherwise, the default mirror returned from Mirror.init(reflecting:) is used, which will either come from the type's CustomReflectable conformance, or from the default mirror representation of the value.

Parameters

value T

The value to output to the target stream.

name String?

A label to use when writing the contents of value. When nil is passed, the label is omitted. The default is nil.

indent Int

The number of spaces to use as an indent for each line of the output. The default is 0.

max​Depth Int

The maximum depth to descend when writing the contents of a value that has nested components. The default is Int.max.

Returns

The instance passed as value.