<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/CustomDebugStringConvertible",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s28CustomDebugStringConvertibleP"
  },
  "title" : "CustomDebugStringConvertible"
}
-->

# CustomDebugStringConvertible

A type with a customized textual representation suitable for debugging
purposes.

```
protocol CustomDebugStringConvertible
```

## Overview

Swift provides a default debugging textual representation for any type.
That default representation is used by the `String(reflecting:)`
initializer and the `debugPrint(_:)` function for types that don’t provide
their own. To customize that representation, make your type conform to the
`CustomDebugStringConvertible` protocol.

Because the `String(reflecting:)` initializer works for instances of *any*
type, returning an instance’s `debugDescription` if the value passed
conforms to `CustomDebugStringConvertible`, accessing a type’s
`debugDescription` property directly or using
`CustomDebugStringConvertible` as a generic constraint is discouraged.

> Note: Calling the `dump(_:_:_:_:)` function and printing in the debugger
> uses both `String(reflecting:)` and `Mirror(reflecting:)` to collect
> information about an instance. If you implement
> `CustomDebugStringConvertible` conformance for your custom type, you may
> want to consider providing a custom mirror by implementing
> `CustomReflectable` conformance, as well.

# Conforming to the CustomDebugStringConvertible Protocol

Add `CustomDebugStringConvertible` conformance to your custom types by
defining a `debugDescription` property.

For example, this custom `Point` struct uses the default representation
supplied by the standard library:

```
struct Point {
    let x: Int, y: Int
}

let p = Point(x: 21, y: 30)
print(String(reflecting: p))
// Prints "Point(x: 21, y: 30)"
```

After adding `CustomDebugStringConvertible` conformance by implementing the
`debugDescription` property, `Point` provides its own custom debugging
representation.

```
extension Point: CustomDebugStringConvertible {
    var debugDescription: String {
        return "(\(x), \(y))"
    }
}

print(String(reflecting: p))
// Prints "(21, 30)"
```

## Relationships

### Conforming Types

[`ObjectIdentifier`](/documentation/Swift/ObjectIdentifier)

[`Scalar`](/documentation/Swift/Unicode/Scalar)

[`DecodingError`](/documentation/Swift/DecodingError)

[`UnsafeMutableBufferPointer`](/documentation/Swift/UnsafeMutableBufferPointer)

[`ArraySlice`](/documentation/Swift/ArraySlice)

[`SIMD2`](/documentation/Swift/SIMD2)

[`SIMD16`](/documentation/Swift/SIMD16)

[`SIMD32`](/documentation/Swift/SIMD32)

[`Array`](/documentation/Swift/Array)

[`Character`](/documentation/Swift/Character)

[`Keys-swift.struct`](/documentation/Swift/Dictionary/Keys-swift.struct)

[`KeyPath`](/documentation/Swift/KeyPath)

[`ReferenceWritableKeyPath`](/documentation/Swift/ReferenceWritableKeyPath)

[`CVaListPointer`](/documentation/Swift/CVaListPointer)

[`Float16`](/documentation/Swift/Float16)

[`WordPair`](/documentation/Synchronization/WordPair)

[`SIMD8`](/documentation/Swift/SIMD8)

[`ClosedRange`](/documentation/Swift/ClosedRange)

[`UTF16View`](/documentation/Swift/String/UTF16View)

[`String`](/documentation/Swift/String)

[`CollectionOfOne`](/documentation/Swift/CollectionOfOne)

[`UnsafeMutableRawPointer`](/documentation/Swift/UnsafeMutableRawPointer)

[`Float`](/documentation/Swift/Float)

[`AnyHashable`](/documentation/Swift/AnyHashable)

[`UnicodeScalarView`](/documentation/Swift/String/UnicodeScalarView)

[`UnsafeMutablePointer`](/documentation/Swift/UnsafeMutablePointer)

[`UnsafeRawPointer`](/documentation/Swift/UnsafeRawPointer)

[`Index`](/documentation/Swift/String/Index)

[`SIMD64`](/documentation/Swift/SIMD64)

[`SIMD4`](/documentation/Swift/SIMD4)

[`Substring`](/documentation/Swift/Substring)

[`Double`](/documentation/Swift/Double)

[`Float80`](/documentation/Swift/Float80)

[`AutoreleasingUnsafeMutablePointer`](/documentation/Swift/AutoreleasingUnsafeMutablePointer)

[`WritableKeyPath`](/documentation/Swift/WritableKeyPath)

[`OpaquePointer`](/documentation/Swift/OpaquePointer)

[`UnsafeBufferPointer`](/documentation/Swift/UnsafeBufferPointer)

[`Range`](/documentation/Swift/Range)

[`SIMD3`](/documentation/Swift/SIMD3)

[`Optional`](/documentation/Swift/Optional)

[`UnsafePointer`](/documentation/Swift/UnsafePointer)

[`StaticBigInt`](/documentation/Swift/StaticBigInt)

[`EncodingError`](/documentation/Swift/EncodingError)

[`AnyKeyPath`](/documentation/Swift/AnyKeyPath)

[`UTF8View`](/documentation/Swift/String/UTF8View)

[`StaticString`](/documentation/Swift/StaticString)

[`PartialKeyPath`](/documentation/Swift/PartialKeyPath)

[`Dictionary`](/documentation/Swift/Dictionary)

[`UnsafeMutableRawBufferPointer`](/documentation/Swift/UnsafeMutableRawBufferPointer)

[`ContiguousArray`](/documentation/Swift/ContiguousArray)

[`UnsafeRawBufferPointer`](/documentation/Swift/UnsafeRawBufferPointer)

[`Values-swift.struct`](/documentation/Swift/Dictionary/Values-swift.struct)

[`KeyValuePairs`](/documentation/Swift/KeyValuePairs)

[`Set`](/documentation/Swift/Set)

### Inherited By

[`CodingKey`](/documentation/Swift/CodingKey)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)