0Pricing
Swift Academy · Lesson

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

  1. CustomStringConvertible
  2. CustomDebugStringConvertible
  3. Reflection with Mirror
  4. Building Debug-Friendly Types
← Back to Swift Academy