so - I can't for the life of me work out how to debug a preview in Xcode 13
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
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?
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.
Go to Xcode → Preferences → Debugging → On Start → "Show Console".
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.
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.
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.
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.
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.
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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With