A type with a customized textual representation suitable for debugging purposes.
- Xcode 7.0+
Swift provides a default debugging textual representation for any type. That default representation is used by the
String(reflecting:) initializer and the
debug function for types that don’t provide their own. To customize that representation, make your type conform to the
String(reflecting:) initializer works for instances of any type, returning an instance’s
debug if the value passed conforms to
Custom, accessing a type’s
debug property directly or using
Custom as a generic constraint is discouraged.
Conforming to the CustomDebugStringConvertible Protocol
Custom conformance to your custom types by defining a
For example, this custom
Point struct uses the default representation supplied by the standard library:
Custom conformance by implementing the
Point provides its own custom debugging representation.