ChatGPT for macOS can now work with Xcode
And it’s great to start a quick chat about your current code!
The ChatGPT macOS app got updated with a nice new integration with a few apps, including Xcode!
If you’re not yet using Cursor or the Xcode GitHub Copilot extension, this is probably great news for you. Without changing anything to Xcode, you can now easily invoke ChatGPT with your current file or selected lines as context for your next prompt.
It works best with that Chat Bar feature, so it’s important that you configure it to a shortcut you’re comfortable with (and that does not conflict… which is hard to come by those days)
How does it work technically? With the macOS accessibility API, of course!
Enabling ChatGPT to work with most compatible apps requires the macOS Accessibility API to query content. This also means you can disable the feature for those apps by disabling Accessibility permissions for ChatGPT in settings.
Once you enable the permission, launch ChatGPT, start a new chat, or trigger the chat bar using your keyboard shortcut.
Click the icon shown in the screenshot above and pair it with Xcode.
Now that this is done, we can dig into this integration's various features!
When you invoke it, it always has access to your currently focused file, so you can start a chat by asking any question related to your current file.
In this case, I’ve asked it to tell me how we would refactor the ugly HTML two Markdown I have in Ice Cubes for rendering Mastodon posts as markdown AttributedString. While this is not like Cursor, where it can edit files in place and make a diff or change, you can still easily copy/paste the code it suggests. You can also continue to iterate on your desired result in the chat window. This is a nice companion assistant instead of trying to be a full-fledged replacement for Xcode.
You can also focus on a selection of lines. Whenever you make a selection in Xcode, use your shortcut to invoke the chat interface, and you’ll see your focused lines.
Here, I’ve asked how I could make the detection for Threads.net URL more robust in my code.
Whether you like the answer or not is not relevant in the context of that article. But that could be something to study for one of my next story.
Note: Those new features in the macOS app are behind the pro subscription for now.
The flow is really well done. It’s easy to invoke and easy to start a new chat. It’s interesting to see the OpenAI desktop team focus on those kinds of workflows, and it makes me wonder if one day they’ll try to enter the code editor business.
Let me know if this changes how you integrate ChatGPT in your day-to-day workflows!
Happy Coding 🚀