Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug a preview in Xcode 13 or Xcode 12

Tags:

xcode

swiftui

so - I can't for the life of me work out how to debug a preview in Xcode 13

preview

I can find all sorts of documentation for Xcode 11, which is very different - and even documentation for Xcode 12 with all sorts of conflicting advice like

  • right click the run button and you'll get a menu
  • control/command/option click run
  • long click the run

Well - I've tried all of those - and put breakpoints on almost every line of code in my preview / view / init functions - and however I hit run, it just... runs... - so I see the preview, but no breakpoints are hit - no print statements come out in the console - no cool expanded ui display appears - and no menus appear.

any ideas?

like image 845
Darren Oakey Avatar asked Jun 26 '21 00:06

Darren Oakey


People also ask

How do I debug preview in Xcode?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.

How do I open the console in Xcode 12?

Go to Xcode → Preferences → Debugging → On Start → "Show Console".

What is Xcode previews used for?

Now Xcode Previews is a new feature of Xcode that allows you to - that institute - minimize the amount of time you spend building and running and configuring your views to verify the changes that you are making. And to - and lets you focus on the things that you love doing best, which is building great apps.

How do I preview a code in Xcode?

Xcode shows the preview in a canvas beside your code. You can use view modifiers to configure the preview, including a set of preview-specific modifiers, like previewDevice (_:) and previewInterfaceOrientation (_:). Xcode also reflects changes that you make in the canvas back into your code.

How do I debug an app in Xcode?

Then using the simulator alone (not Xcode) click on the AppName to let it run. Then go into Xcode and do Debug > Attach to process by PID. Then type in the name of your App, and click Attach. Then press the Pause icon in Xcode Debug Navigator.

How to add debugger to previewed app?

Instead, use the Debug > Attach to Process menu item to attach the debugger to your previewed app. (73981969) That doesn't seem to work for me in Xcode 13.1.

Should I switch from iOS 12 support to Xcode previews?

Although the workflow requires you to switch the OS version, it does allow you to use the Xcode previews. This can improve development speed and allows you to start working with Xcode Previews before you drop iOS 12 support. If you like to improve your SwiftUI knowledge, even more, check out the SwiftUI category page.


2 Answers

It looks like Apple has chosen to remove the ability to debug Xcode Previews in Xcode 13 with no guidance as to if/when it will be brought back.

Hi, The ability to use a debugger for previews has unfortunately been removed. > As you pointed out, the workaround is to run the app in the simulator. Sorry for any inconvenience caused!

Posted 1 month ago by Frameworks Engineer 

https://developer.apple.com/forums/thread/683773

like image 165
Josh Brunner Avatar answered Oct 25 '22 09:10

Josh Brunner


You can attach the Debugger to the Preview Process like explained here

Deprecations Xcode 13 no longer includes a menu item in the Previews canvas for debugging a preview. Instead, use the Debug > Attach to Process menu item to attach the debugger to your previewed app. (73981969)

like image 30
Celina Avatar answered Oct 25 '22 09:10

Celina