Member-only story
print() vs dump()
1 min readOct 2, 2020
Many of us start debugging with simple print(). Let’s say we have such a class:
class Abc {
let a = "aa"let b = “bb” }
and we have an instance of Abc as so:
let abc = Abc()
When we run the print() on the variable, the output is
App.Abc
while dump() outputs
App.Abc #0
- a: "aa"
- b: "bb"
As seen, dump() outputs the whole class hierarchy, while print() simply outputs the class name.
Therefore, dump() is especially useful for UI debugging
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
With dump(view) we get:
- <UIView: 0x108a0cde0; frame = (0 0; 100 100); layer = <CALayer: 0x159340cb0>> #0
- super: UIResponder
- NSObject
While print(view) we get:
<UIView: 0x108a0cde0; frame = (0 0; 100 100); layer = <CALayer: 0x159340cb0>>
There is more info on the class with dump(), and so it is more useful in debugging the class itself.