CustomDebugStringConvertible
Provide richer debug output.
A Separate Debug View
CustomDebugStringConvertible provides debugDescription — the representation used by debugPrint, the LLDB po command, and the debugger. It can be more detailed than description.
Adding debugDescription
Conform and supply the property:
struct Point: CustomDebugStringConvertible {
let x: Int
let y: Int
var debugDescription: String { "Point(x: \(x), y: \(y))" }
}
debugPrint(Point(x: 1, y: 2)) // Point(x: 1, y: 2)All lessons in this course
- CustomStringConvertible
- CustomDebugStringConvertible
- Reflection with Mirror
- Building Debug-Friendly Types