<!--
{
  "documentType" : "article",
  "framework" : "Swift Playgrounds",
  "identifier" : "/documentation/Swift-Playgrounds/console-print-debugging",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Debugging an App Playground using the Console"
}
-->

# Debugging an App Playground using the Console

Learn different methods to debug your code using console output.

## Overview

When writing code in Swift Playgrounds, you can debug your playgrounds by using print statements and viewing their output in the console. You can filter statements in the console to find specific outputs.

## Add a print statement

Call `print(_:separator:terminator)` in the code you’d like to debug and add any items you’d like to output to the console. These items output as `String` values, the same as the output obtained by calling `String(item)`. To customize your debug output for any type, you can add [CustomDebugStringConvertible](https://developer.apple.com/documentation/swift/customdebugstringconvertible) conformance to provide your own implementation for `debugDescription`. This allows you to print custom `String` representations for any type and view them in the console.

If you’re trying to debug a SwiftUI view, you need to adjust your approach. Because SwiftUI is a [declarative framework](https://developer.apple.com/documentation/swiftui/state-and-data-flow), you can’t add an imperative `print` call inside your view declaration. This is because the view `body` property expects to return a [View](https://developer.apple.com/documentation/swiftui/view) value. To resolve this, you can use one of several approaches.

One approaach to debug your declarative code is to attach the `onAppear(perform:)` modifier to a view in your `body`, and call `print` when the view first appears:

```
Image(systemName: "globe")
    .onAppear {
        print("This is the debug output.")
    }
```

You could also add an extension on `View` that returns itself and calls the `print` method:

```
extension View {
    func printOutput(_ value: Any) -> Self {
        print(value)
        return self
    }
}
```

You can then use `printOutput` as a view modifier to print debug information to the console when the view is built:

```
VStack {
   ForEach(colors, id: \.self) { color in
      Circle()
         .foregroundColor(color)
         .printOutput(color)
   }
}
```

## Understand when and why your views change

Another approach that’s particularly useful when debugging SwiftUI view updates is to call the internal method `Self._printChanges()` from the `body` of the view — instead of calling `print`. This records which property caused the view to update and sends that information to the console. In addition to providing property names, `@self` marks the change to the view value, and `@identity` marks the change to the view’s identity.

```
var body: some View {
    let _ = Self._printChanges()
    // View code 
}
```

## See your app’s output in the Console

Press the console button in the code editor to show and hide the console. To adjust the size of the console, you can drag to increase or decrease the available space.

![The Swift Playgrounds code editor displaying console output](images/com.apple.Swift-Playgrounds/console@2x.png)

To filter results, tap the filter button and enter a phrase you’d like to filter on. The remaining results filter based upon this input.

You can tap to select a result, which allows you to select it as text or to clear the console output by deleting the text.

---

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)