dump

suggest change

dump prints the contents of an object via reflection (mirroring).

Detailed view of an array:

let names = ["Joe", "Jane", "Jim", "Joyce"]
dump(names)

Prints:

▿ 4 elements

- [0]: Joe

- [1]: Jane

- [2]: Jim

- [3]: Joyce

For a dictionary:

let attributes = ["foo": 10, "bar": 33, "baz": 42]
dump(attributes)

Prints:

▿ 3 key/value pairs

▿ [0]: (2 elements)

▿ [1]: (2 elements)

▿ [2]: (2 elements)

dump is declared as dump(_:name:indent:maxDepth:maxItems:).

The first parameter has no label.

There’s other parameters available, like name to set a label for the object being inspected:

dump(attributes, name: "mirroring")

Prints:

▿ mirroring: 3 key/value pairs

▿ [0]: (2 elements)

▿ [1]: (2 elements)

▿ [2]: (2 elements)

You can also choose to print only a certain number of items with maxItems:, to parse the object up to a certain depth with maxDepth:, and to change the indentation of printed objects with indent:.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents