How to Automatically Connect Debugger to Extension and App

There is a convenient way to automatically connect the debugger in Xcode to a file provider extension and its host app process on run.

I assume debugging multiple processes in Xcode is not the daily situation most developers for macOS and iOS find themselves in. It quickly happens when you start to ship extensions, though. In the past I (and my collegues) connected to other processes, in example extensions, via Xcode’s “Debug” menu, attaching by name. This is annoying in the long run. Especially if you change the code of your extension and rebuild frequently. So a small relief is to set up a keyboard shortcut in Xcode’s settings for attaching by name to not always go through the app menu. But this still is tiresome. Recently I filed a feedback in Apple’s Feedback Assistant wishing for automatic connection to multiple processes on run. To my surprise, I received an answer. That was the first feedback response in years and a dozen reports. Xcode can actually do it in a certain way. Xcode can automatically attach to XPC services used by a debugged app.

Example Project

These are steps to set up an example project.

  1. Create a new Xcode project from the macOS app template. In my example I named it “YetAnotherDrive”.
  2. Add a new target to the project from the file provider extension template. In my example I named it “YetAnotherDriveFileProvider”.
  3. On creation Xcode asks whether to activate the scheme of the file provider extension. Confirm that because this is the way we want to go.

Great, now we have a basic macOS app with a file provider extension. Now, if you run the scheme Xcode just asks you for an app to run. You can choose from a list of installed apps but your project’s main app is not listed.

Tweaking Settings

Cancel that prompt and edit the scheme of the file provider extension instead.

Screenshot of Xcode's scheme selector

Select the “Run” action and its “Info” tab. You will see that the Executable is set to “Ask on Launch”. You This is what I described and experienced earlier. Select the hosting app in this popup menu and check “Debug executable” below that menu. Just to double check: In the “Options” tab, verify “Debug XPC services used by app” is enabled.

Screenshot of Xcode's scheme run action information

Now you can run the file provider extension scheme and it will launch the hosting app. As you can see in the debug navigator, Xcode is ready to debug two processes at once. But wait, why the debugger still waiting to attach to the extension?

Screenshot of Xcode waiting to attach to process

This is less in scope of this post but more of another in which I wrote about how to implement a rudimentary file provider extension. Your main app does not actually use or connect to the file provider extension yet. Also the file provider extension itself is not yet completely fit for XPC.

Following these steps with my example project, you can see this working with Xcode connecting to both running processes automatically on run.

About The Author

Peter Thomas Horn is a professional software developer at Open-Xchange specialized on the Apple platform. He previously worked a decade across the full stack of various web technologies. Originally started with Java on Windows at the age of 12 years. While staying humble in throwing around buzzwords like "VR" and "machine learning" he occasionally experiences problems and the fitting solutions considered worth sharing.