<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/debugging-and-reflection",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Debugging and Reflection"
}
-->

# Debugging and Reflection

Fortify your code with runtime checks, and examine your values’ runtime representation.

## Topics

### Printing and Dumping

[`print(_:separator:terminator:)`](/documentation/Swift/print(_:separator:terminator:))

Writes the textual representations of the given items into the standard
output.

[`print(_:separator:terminator:to:)`](/documentation/Swift/print(_:separator:terminator:to:))

Writes the textual representations of the given items into the given output
stream.

[`debugPrint(_:separator:terminator:)`](/documentation/Swift/debugPrint(_:separator:terminator:))

Writes the textual representations of the given items most suitable for
debugging into the standard output.

[`debugPrint(_:separator:terminator:to:)`](/documentation/Swift/debugPrint(_:separator:terminator:to:))

Writes the textual representations of the given items most suitable for
debugging into the given output stream.

[`dump(_:name:indent:maxDepth:maxItems:)`](/documentation/Swift/dump(_:name:indent:maxDepth:maxItems:))

Dumps the given object’s contents using its mirror to standard output.

[`dump(_:to:name:indent:maxDepth:maxItems:)`](/documentation/Swift/dump(_:to:name:indent:maxDepth:maxItems:))

Dumps the given object’s contents using its mirror to the specified output
stream.

### Testing

[`assert(_:_:file:line:)`](/documentation/Swift/assert(_:_:file:line:))

Performs a traditional C-style assert with an optional message.

[`assertionFailure(_:file:line:)`](/documentation/Swift/assertionFailure(_:file:line:))

Indicates that an internal consistency check failed.

[`precondition(_:_:file:line:)`](/documentation/Swift/precondition(_:_:file:line:))

Checks a necessary condition for making forward progress.

[`preconditionFailure(_:file:line:)`](/documentation/Swift/preconditionFailure(_:file:line:))

Indicates that a precondition was violated.

### Exiting a Program

[`fatalError(_:file:line:)`](/documentation/Swift/fatalError(_:file:line:))

Unconditionally prints a given message and stops execution.

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

A type that has no values and can’t be constructed.

### Querying Runtime Values

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

A representation of the substructure and display style of an instance of
any type.

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

A unique identifier for a class instance, actor instance, or metatype.

[`type(of:)`](/documentation/Swift/type(of:))

Returns the dynamic type of a value.

### Customizing Your Type’s Reflection

Provide a custom reflection for your types using these protocols.

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

A type that explicitly supplies its own mirror.

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

A type that explicitly supplies its own mirror, but whose
descendant classes are not represented in the mirror unless they
also override `customMirror`.

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

A type that supplies a custom description for playground logging.

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

The sum of types that can be used as a Quick Look representation.

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

Converts description definitions to a debugger Type Summary.



---

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)