0Pricing
Swift Academy · Lesson

CustomStringConvertible

Define a readable description for your types.

What Is CustomStringConvertible?

This protocol lets you control how your type appears when printed or interpolated into a string. You provide a description property.

The Default Is Ugly

Without it, structs print their full memberwise form, which is often noisy:

struct Point { let x: Int; let y: Int }
print(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