Debug Previews

I used to be able to "right click" on the play button for a preview, but in Beta 1 and 2 of Xcode 13 that isn't working (neither is control clicking). Any ideas how to debug a preview short of running app in the simulator?

Post not yet marked as solved Up vote post of Whootang12 Down vote post of Whootang12
6.5k views

Replies

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!

  • Thanks for clarifying. Is this expected to return or has it been removed from Xcode 13?

  • I cannot comment on future intentions, but I can confirm that it was removed intentionally and it is not a bug that it is no longer there.

  • This is kind of a terrible workaround, as it can be tedious or impossible to get to that view in the full app (perhaps the path to it has not yet been implemented). I don't mind if it launches in the simulator, but I'd really need Xcode to to grab the preview and present that.

Thanks for clarifying @FrameworksEngineer.

If that is the case, it would be good to make a note at the top of this document: https://developer.apple.com/news/?id=8vkqn3ih

Since lots of SO and blog posts mention this "one weird trick" of right clicking the run button, something clear that mentions its deprecation would be good. Feedback Filed: FB9632206

Also: PSA for anyone coming here, a workaround I've started using is the Logger() api + Console app. Note that your log level seemingly must be .info or higher for Simulator / Preview logs to show on the host Mac's Console (whereas .debug is sufficient for attached physical devices.)

  • @alexfringes Could you clarify how you are getting the logs? Where do they show up in console? Thanks! Greg

  • Would you please explain a bit how do you get Mac's Console app to display the Logger() information under SwiftUI's Live Preview? I tried different stuffs in order to show debugging information at under a Live Preview, but none of them works. The Logger API has no issue when running the app in simulator, but like some people mentioned, sometimes the View does not even have a path from the App's home view, or it could take very long time to get to a specific View. It'd be great if you could share some tips.

Add a Comment

The XCode 13 RC release notes do mention following in the preview section:

Previews

...

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)

However, there are no instructions anywhere on how to find the process to attach to. I tried attaching to XCPreviewAgent process that seems to be spawned when I switch into run mode. Only to be hit by permission failures to debug.

  • The error in console.app is:

    macOSTaskPolicy: (com.apple.debugserver) may not get the task control port of (XCPreviewAgent) (pid: 12984): (XCPreviewAgent) is hardened, (XCPreviewAgent) doesn't have get-task-allow, (com.apple.debugserver) is a declared debugger(com.apple.debugserver) is not a declared read-only debugger
  • You can workaround the limitations of XCPreviewAgent https://developer.apple.com/forums/thread/690415?answerId=689090022#689090022

Add a Comment