print vs dump
suggest changeMany 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()
print on that value produces:
App.Abc
dump produces:
▿ App.Abc #0
- a: "aa"
- b: "bb"
print shows the type name. dump uses reflection to show stored properties, and the superclass chain when there is one.
dump is especially useful when debugging views.
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
print(view) produces:
<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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents