LAST CHANCE: Save 50% on all my Swift books and bundles! >>

SOLVED: Do print statements not work when using previews?

Forums > 100 Days of SwiftUI

If I have a print statement in a function, it will print to the console when running the app in the simulator, but it won't when using the preview.

Is there anyway to get print statements to work when using previews? It's a bit annoying to have to run in the simulator over and over again because the simulator hides xcode so I can't see the console. Using the preview would be much faster.

I saw a stackoverflow post that says you have to capture the void return value of the print function like this:

let _ = print("Test")

But that had no effect.

2      

Do print statements not work when using previews?

Nope.

2      

That's a shame. I'm new to Macs in general (coming from Windows) so I'm trying to figure out a process to streamline debugging. My lack of familiarity with macos is likely making things worse.

I'm working on a macbook and I've got xcode maximized for screen real estate. When I run the build, xcode is swept off screen and I'm left with just the simulator. Then when I close (or rather click the red window button, I'm still not clear if that's "closing" in macos) the simulator, oddly, debugging doesn't stop and I have to then hit stop, and select folder view to be able to navigate between files in the project again.

Ideally, running the build would place the simulator in front of xcode and closing the simulator would return me to xcode with debugging stopped and folder view restored. Is this possible?

2      

Hi Legion. I went through the same thing when i started. It's because you are in full screen. In the top left hit the green button to exit full screen mode. Then you can drag the Xcode window around. Put it in the top left and drag the window on the bottom right to take up the full screen. Now when you run the simulator it will appear in front of the Xcode window. You can drag the simulator at the top, to the left side of the screen and see and scroll the debug window. Cmd +1, 2 or 3 will change the simulator size and cmd + q will exit. Be careful using cmd + q it will also exit Xcode if you push it too many times.

Hope that helps

3      

Thanks @WileECodee!

2      

2      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until July 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.