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
- CustomStringConvertible
- CustomDebugStringConvertible
- Reflection with Mirror
- Building Debug-Friendly Types