How to print into the console in SwiftUI?

Hi guys! Can you help me about this? Thanks

You'll need to turn on Debug Preview: right-click on the live preview play button and select "Debug Preview" from the popup.

1 Like

Thanks Amritpan, I have Xcode 12.1 and this feature don´t work. It seems is a Xcode bug.
https://developer.apple.com/forums/thread/654334

1 Like

How to print () to Xcode console in SwiftUI ?, Try right-clicking on the live preview play button and selecting 'Debug Preview from the popup. The print function prints messages in the Xcode console when debugging apps.

There are a Xcode bug when I try this... :neutral_face:

Debug preview doesn't show print in console. I run in the simulator or device.

This might be helpful: Building SwiftUI debugging utilities | Swift by Sundell

1 Like

Thanks!

Thanks this works for me

expresshr

I have the same problem as @Luko . My Xcode 12 still won't print, even in Debug Preview mode, and even when I use the tips from Building SwiftUI debugging utilities | Swift by Sundell

Print isn't even working for me when I'm running from the simulator, which is weird because it used to work before for me.

Has anyone ever got this feature working? I’ve never been able to debug previews.

They seem to have removed easy preview debugging in Xcode 13 for some reason. Now they say to attach to the preview process manually from Xcode. Haven’t tried it but it worked in Xcode 12, usually.

Debug preview is gone: Debug Previews | Apple Developer Forums

How to do this?

I just run in simulator or device

Yea every time I tried in Xcode 12 it just fails to attach.

Same thing happens with the view debugger in storyboards.