Home > Blockchain >  How to print to the Debug Area with Swift UI in Xcode 13?
How to print to the Debug Area with Swift UI in Xcode 13?

Time:04-04

I want my print message to be shown in the Debug Area in Xcode 13. There are several questions like this on StackOverflow, some of them suggest using the Debug Mode, which seems to have been removed in Xcode 13.

Here is my ContentView:

struct ContentView: View {
    var body: some View {
        Button("button", action: {
            print("abc")
        })
    }
}

Though I use print("abc"), when I click the button, there's nothing in the Debug Area. How to show it?

Debug Area

CodePudding user response:

The problem is that you're not running the app. You're just looking at the preview. Press Command-R and run the app in a simulator; tap the button in the simulator.

Note that when you're actually running the app, the debug bar (at the top of the debug area) looks quite different:

enter image description here

CodePudding user response:

Try let _ = print(“abc”) in place of your current print statement

  • Related