protocol
CustomDebugStringConvertible
Inheritance | View Protocol Hierarchy → |
---|---|
Import |
|
Instance Variables
var debugDescription: String Required
A textual representation of this instance, suitable for debugging.
Declaration
var
debugDescription
:
String
{
get
}
A type with a customized textual representation suitable for debugging purposes.
Swift provides a default debugging textual representation for any type. That default representation is used by the
String(reflecting:)
initializer and thedebugPrint(_:)
function for types that don't provide their own. To customize that representation, make your type conform to theCustomDebugStringConvertible
protocol.Because the
String(reflecting:)
initializer works for instances of any type, returning an instance'sdebugDescription
if the value passed conforms toCustomDebugStringConvertible
, accessing a type'sdebugDescription
property directly or usingCustomDebugStringConvertible
as a generic constraint is discouraged.Conforming to the CustomDebugStringConvertible Protocol
Add
CustomDebugStringConvertible
conformance to your custom types by defining adebugDescription
property.For example, this custom
Point
struct uses the default representation supplied by the standard library:After adding
CustomDebugStringConvertible
conformance by implementing thedebugDescription
property,Point
provides its own custom debugging representation.See Also:
String.init<T>(reflecting: T)
,CustomStringConvertible