dump
suggest changedump 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
- "Joe"
- "Jane"
- "Jim"
- "Joyce"
For a dictionary:
let attributes = ["foo": 10, "bar": 33, "baz": 42]
dump(attributes)
Prints (dictionary order is not guaranteed and can differ between runs):
▿ 3 key/value pairs
▿ (2 elements)
- key: "bar"
- value: 33
▿ (2 elements)
- key: "baz"
- value: 42
▿ (2 elements)
- key: "foo"
- value: 10
dump is declared as dump(_:name:indent:maxDepth:maxItems:).
The first parameter has no label.
Other parameters are available. name sets a label for the object being inspected:
dump(attributes, name: "mirroring")
Prints:
▿ mirroring: 3 key/value pairs
▿ (2 elements)
- key: "bar"
- value: 33
▿ (2 elements)
- key: "baz"
- value: 42
▿ (2 elements)
- key: "foo"
- value: 10
maxItems: limits how many items are printed, maxDepth: limits how deep the dump goes, and indent: sets the indentation.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents